EWAttachFromSOAPAttachment
Attaches a file into a field of the table record in your knowledgebase.
Syntax
int n = ew.EWAttachFromSOAPAttachment(String sessionId, String tableName, long id, String fieldName, String fileName);
Usage
Use the EWAttachFromSOAPAttachment call to attach a file passed as a SOAP attachment into a file or image field in the table using the specified file name.
Rules and Guidelines
When attaching files, consider the following rules and guidelines:
- The username that was used to obtain the specified session token must have sufficient access rights to modify individual records within the specified table. Please verify specific permissions via Setup > Access > Manage Groups > (Edit Group) > Table > (Edit Table) > Permissions.
- Agiloft allows specifying fine-grained access permissions on the field level. The username that was used to obtain the specified session token must have sufficient access rights to be able to update the field content. Please verify specific permissions via Setup > Access > Manage Groups > (Edit Group) > Table > (Edit Table) > Field Permissions.
- This call returns the current number of the attached files in the specified field.
- One can use EWRead method to obtain an array of file names for the attached fields in the specified field.
- Only one file per call is attached.
- The file name does NOT have to be unique across multiple calls against the same record and field.
- In general, you use EWAttachFromSOAPAttachment when you know in advance the identifiers of the records to retrieve. The client application may use the likes of EWSelectFromTable call to obtain record identifiers beforehand or to take the identifiers from the id field of the data structures and linking classes.
Basic Steps for Attaching Files
Attaching files to records involves the following basic steps:
- Determine the id of the record you want to update. You may want to use the EWSelectFromTable or EWSearchTable calls to get the identifiers of the records based on some search condition or get the identifier from a previous EWCreate call, or get the id of a linked record from the linking class after performing EWRead or EWUpdate.
- Wrap your file on the client-side in the matter specific to your client-side SOAP environment.
- Call EWAttachFromSOAPAttachment.
- Process the results.
Example Task
In MyKB knowledgebase as user A, attach from the client-side filesystem file B.txt located in the current directory to the field Additional Files of case #456 and return the total number of files currently attached.
The task is completed by performing the following steps:
- Login to MyKB with "A" and "password" and English as the local language.
- Prepare the file for transmission.
- Invoke attach call.
- Get total number of files currently attached.
- Logout.
Sample Code - Java
You can generate sample Web Services code for any table by selecting Setup > Tables > (Edit Table) > API > Download Sample.
public int attach() throws Exception { EWServiceAPI binding = new EWServiceAPIServiceLocator().getDemo(); try { String sessionId = binding.EWLogin("MyKB", "A", "password", "en"); DataHandler dataHandler = new DataHandler(new FileDataSource("B.txt")); binding.addAttachment(dataHandler); int n = binding.EWAttachFromSOAPAttachment(sessionId, "case", 456, "additional_files", "B.txt"); return n; } finally { binding.EWLogout(sessionId); } }
Arguments
Note: The file to be attached is passed as a SOAP attachment.
Name | Type | Description |
---|---|---|
sessionId | String | Session token |
tableName | String | The name of the table where the record is. |
id | long | The identifier of the record to attach files to. |
fieldName | String | The name of the field to attach files to. |
fileName | String | The name of the file to be used in File or Image field. |
Response
The current number of files attached in the specified field.
Faults
EWSessionException - client not logged in or session has expired; client should re-login.
EWPermissionException - user used to create the session lacks sufficient privileges to read the record.
EWWrongDataException - client has supplied wrong data, for instance ID cannot be found.
EWOperationException - the operation has been blocked by one of Agiloft functionalities, for example a table-level lock.
EWIntegrityException - specified table cannot be found or its primary key cannot be identified.
EWUnexpectedException - an unexpected exception has happened; user should report this for investigation.