Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This server class provides methods that allow operating with attachments.
SimpleAttachment()
Instantiates a new empty SimpleAttachment object.
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const attach = new SimpleAttachment(); |
base64Decode(data)
This method returns an ASCII string decoded from the base64 string specified.
Name | Type | Mandatory | Default Value |
---|---|---|---|
data | String | Y | N |
Return:
Type | Description |
---|---|
String | The decoded string. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const attach = new SimpleAttachment();
const result = attach.base64Decode('TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=');
ss.info(result);
// Info: Lorem ipsum dolor sit amet |
base64Encode(data)
This method returns a Base64 string from the string specified.
Name | Type | Mandatory | Default Value |
---|---|---|---|
data | String | Y | N |
Return:
Type | Description |
---|---|
String | The encoded Base64 string. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
constlet attach = new SimpleAttachment(); const result = attach.base64Encode('Lorem ipsum dolor sit amet'); ss.info(result); // Info: TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ= |
copy(
sourceTablesourceTableName, sourceID,
targetTabletargetTableName, targetID)
This method copies attachments from the source record to the target record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
sourceTablesourceTableName | String | Y | N |
sourceID | String | Y | N |
targetTabletargetTableName | String | Y | N |
targetID | String | Y | N |
Return:
Type | Description |
---|
Boolean | This method |
returns TRUE if attachments copied successfully; otherwise, it returns FALSE. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
constlet attach = new SimpleAttachment(); attach.copy('usersys_email', '155964310500000059', 'sys_scripttask', '155964310500000051'current.sys_id); |
deleteAttachment(attachmentID)
This method deletes the specified attachment.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
attachmentID | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
letconst attach = new SimpleAttachment(); attach.deleteAttachment('157052637119478714'); |
getAttachmentUrlById(attachmentId)
This method allows to get the URL of the specified attachment at the cloud storage.
Name | Type | Mandatory | Default Value |
---|---|---|---|
attachmentId | string | Y | N |
Return:
Type | Description |
---|---|
String | This method returns the attachment URL in the cloud storage. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const ATTACH_ID = '163553718313772587'; const simpleAttach = new SimpleAttachment(); const attachUrl = simpleAttach.getAttachmentUrlById(ATTACH_ID); ss.info(attachUrl); // Info: https://s3-{your-instance-url}/public-attachment/5/32/9bnc2pcb3axyfatgtc6lsi7... |
getContent(sysAttachment)
This method gets attachment content as a string.
Name | Type | Mandatory | Default Value |
---|---|---|---|
sysAttachment | SimpleRecord | Y | N |
Return:
Type | Description |
---|---|
String | The attachment content as a string. |
Example)
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
letconst attach = new SimpleAttachment(); let content = attach.getContent('157052637119478714');ss.info(attach.getContent('168109939701169218')); // Info: task active additional_comments approval_state ... |
readBase64(attachmentId)
This method allows to get a encoded string from the specified attachment. Together with the writeBase64() method, you can use it to copy attachments.
Note |
---|
The attachment size is limited up to 10 Mb; otherwise, the method throws an exception: |
Parameter(s):
Name | Type | Mandatory | Default value |
---|---|---|---|
attachmentId | String | Y | N |
Return:
Type | Description |
---|---|
String | The base64-encoded string. |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const read = new SimpleAttachment();
ss.info(read.readBase64('168025458107121347'));
// Info: 0YLQtdGB0YLQvtCy0YvQuSDQtNC+0LrRg9C80LXQvdGC |
rename(attachmentId, fileName)
This method renames the specified attachment.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
attachmentId | String | Y | N |
fileName | String | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const DOC_ID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id); const simpleAttachlet attach = new SimpleAttachment(); attach.rename('157052637119478714', 'new_name_1.png'); |
const attachRecord = new SimpleRecord('sys_attachment');
attachRecord.addQuery('record_document_id', DOC_ID);
attachRecord.addQuery('mime_content_type', 'application/json');
attachRecord.selectAttributes('sys_id');
attachRecord.query();
attachRecord.next();
simpleAttach.rename(attachRecord.sys_id, `${current.number} - ${current.subject}.json`); |
write(documentId, fileName, content, contentType)
This method inserts the attachment to the record specified.
Name | Type | Mandatory | Default Value |
---|---|---|---|
recorddocumentId | SimpleRecordString | Y | N |
filename | String | Y | N |
content | String | Y | N |
contentcontentType | String | Y | N |
Return
Type | Description |
---|---|
String | The attachment's sys ID; in case of error; returns NULL. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const simpleAttachlet attach = new SimpleAttachment(); letconst recordattachID = attach simpleAttach.write('157052637119478714', 'readme.md', 'text/markdown', '# h1 title'); ss.getDocIdByIds(current.sys_db_table_id, current.sys_id), 'readme.json', JSON.stringify(current.getAttributes(), null, '\t'), 'application/json' ); |
writeBase64(documentId, fileName, base64, mimeContentType)
This method inserts the attachment to the record specified using Base64 encoding. Together with the readBase64() method, you can use it to copy attachments.
Name | Type | Mandatory | Default Value |
---|---|---|---|
documentID | String | Y | N |
fileName | String | Y | N |
base64 | String | Y | N |
mimeContentType | String | Y | N |
Return
Type | Description |
---|---|
String or NULL | The attachment's sys ID; in case of error; returns NULL. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const CURRENT_USER_DOC_ID = ss.getDocIdByIds(ss.getUser().sys_db_table_id, ss.getUserID());
const simpleAttach = new SimpleAttachment();
const base64Value = 'R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
const attachId = simpleAttach.writeBase64(
CURRENT_USER_DOC_ID,
'file_example.gif',
base64Value,
'image/gif'
);
ss.info(attachId);
//Info: 162245472311776172 |
Table of Contents | ||||
---|---|---|---|---|
|