Topic Options
Rate This Topic
#61610 - 10/16/03 06:03 AM Saving attachmet using the JAVA API
borisg Offline
Just Signed Up

Registered: 11/26/02
Posts: 4
Loc: Sweden
Hi

We are trying to get an attachment in ARS 5.1 and save it to a file using the Java API. But reding the Java API doc doesn't help very munch :-(

BR,
Boris

Top
#61611 - 12/10/03 04:34 PM Re: Saving attachmet using the JAVA API [Re: rongrip]
Matt Reinfeldt Offline
Old Hand
***

Registered: 06/12/01
Posts: 1419
Loc: Madison, WI
here's a piece of sample code that's been shared with me...

Code:

import com.remedy.arsys.api.*;

public class getAttach
{
public static void main(String args[])
{

// Username to login to ARServer
String uname = "Demo";
// Password for the User
String pword = "<your_password>";
// Language
String lang = "";
// ARServer
String serv = "<your_arserver>";
// Create ARServerUser object with supporting information.
ARServerUser context = new ARServerUser(uname, pword, lang, serv);


// Create NameID object adding the form name you wish to retrieve the attachment from in the constructor.
NameID schemaID = new NameID("RESOURCE_Downloads");

// Create EntryID object adding the EntryID of the record you wish to retrieve the attachment from in the constructor
EntryID entryID = new EntryID("000000000000007");

// Create FieldID object adding the fieldID of the attachment field in the constructor
long fid = 536880912;
FieldID fieldID = new FieldID(fid);

// Need to have the Util.ARGetEntryBlob() method in a try block to catch ARException
try
{
// Set a string variable for the name of the attachment
String aname = "ConvertQual.def";
// Set a string variable for the full path of where you wish to copy the attachment to.
String filePath = "C:\\ConvertQual.def";
// Create AttachmentInfo object with supporting information
AttachmentInfo attach = new AttachmentInfo(aname, 0, 0, "");
// Call the setValue() method of the AttachmentInfo object passing in the "full path" string variable.
attach.setValue(filePath);

// Call ARGetEntryBlob with supporting information
Util.ARGetEntryBlob(context, schemaID, entryID, fieldID, attach);
}
catch (ARException e)
{
System.out.println("Exception: " + e.toString());
}

}

}



Hope that helps!
_________________________
Matt Reinfeldt
I belong to the following Professional Networks:
http://www.naymz.com/search/matt/reinfeldt/1524717
http://www.linkedin.com/in/mreinfeldt

Top
#61612 - 03/02/05 08:58 AM Re: Saving attachmet using the JAVA API [Re: Matt Reinfeldt]
MiguelAlgarvio Offline
Just Signed Up

Registered: 03/02/05
Posts: 2
Hello Matt Reinfeldt,

I've been using your sample to get attachment from our ARS Server, and I need to go one step ahead.

In your example, you choose the attachment name.
We need to get the attachment name from the attachment field in our ARS Server.
The JavaDriver example we have (from version 5.1.2) doesn't give us such an example.
Do you know how to do it? Do you know where can we find another example showing what we need?

Thank you,
Miguel Algarvio

Top
#61613 - 03/02/05 10:28 AM Re: Saving attachmet using the JAVA API [Re: epawlyshyn956]
MiguelAlgarvio Offline
Just Signed Up

Registered: 03/02/05
Posts: 2
Sorry to have bother you...

I couldn't wait for an answer and I continue making my tests...

I manage to get what I needed using the following code:

...
EntryFactory entryMan = EntryFactory.getFactory();
EntryCriteria entryCriteria = new EntryCriteria();

// Get the Entry Key (using variables form and entry defined earlier)
EntryKey entryKey = new EntryKey(form, entry);

// Get the fields information
// (1st field is the folder to save the attachment,
// 2nd field is the attachment itself
FieldID[] fieldsList = new FieldID[2];

fieldsList[0] = fieldID; // fieldID was defined earlier
fieldsList[1] = folderID; // folderID was defined earlier

EntryListFieldInfo[] entryList = new EntryListFieldInfo[fieldsList.length];

entryList[0] = new EntryListFieldInfo(fieldsList[0]);
entryList[1] = new EntryListFieldInfo(fieldsList[1]);

entryCriteria.setEntryListFieldInfo(entryList);

Entry attachmentRecord = entryMan.findByKey(context, entryKey, entryCriteria);

EntryItem[] entryItemList = attachmentRecord.getEntryItems();

System.out.println("Folder: " + entryItemList[1].getValue().getValue().toString());

if (entryItemList[0].getValue().getDataType().toInt() == 11) // Just to be sure this field is an attachment
System.out.println("Attachment Name: " + ((AttachmentInfo) entryItemList[0].getValue().getValue()).getName());

...

Regards,
Miguel

Top
#61614 - 03/16/05 02:42 AM Re: Saving attachmet using the JAVA API [Re: Matt Reinfeldt]
Mahi Offline
Just Signed Up

Registered: 03/16/05
Posts: 2
I am new to AR System.I have to write Java Api program in ARS to submit a helpdesk ticket.I want smple code regarding the same.I also want to know where i can get information regarding the ARS Java api calls in detail.Its very urgent.Pls help me out.

Top