This server class provides methods that allow operating with attachments.
SimpleAttachment()
Instantiates a new empty SimpleAttachment object.
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | SimpleAttachment |
---|
linenumbers | true |
---|
|
letconst 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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | base64Decode |
---|
linenumbers | true |
---|
|
letconst attach = new SimpleAttachment();
attach.base64Decode('157052637119478714'); |
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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | base64Encode |
---|
linenumbers | true |
---|
|
letconst attach = new SimpleAttachment();
attach.base64Encode('157052637119478714'); |
copy(sourceTable, sourceID, targetTable, targetID)
This method copies attachments from the source record to the target record.
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
sourceTable | String | Y | N |
sourceID | String | Y | N |
targetTable | String | Y | N |
targetID | String | Y | N |
Return:
Type | Description |
---|
Void | This method does not return a value. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | copy |
---|
|
letconst attach = new SimpleAttachment();
attach.copy('usersys_email', '155964310500000059', 'sys_scripttask', '155964310500000051'); |
createAttachmentByUrl(url, SimpleRecordId, fileName)
Parameter(s):
Name | Type | Mandatory | Default Value |
---|
url | String | Y | N |
SimpleRecordId | String | Y | N |
fileName | String | Y | N |
Return:
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | createAttachmentByUrl |
---|
|
|
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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | deleteAttachment |
---|
|
letconst attach = new SimpleAttachment();
attach.deleteAttachment('157052637119478714'); |
getCloudStorageUrlgetAttachmentUrlById(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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | getCloudStorageUrl |
---|
linenumbers | true |
---|
|
const attach = new SimpleAttachment();
const publicUrl = attach.getAttachmentUrlById('157052637119478714');
ss.info(publicUrl); |
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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | getContent |
---|
|
letconst attach = new SimpleAttachment();
letconst content = attach.getContent('157052637119478714'); |
readBase64(attachmentId)
This method allows to get a encoded string from the specified attachment.
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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | readBase64 |
---|
linenumbers | true |
---|
|
|
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 |
---|
language | js |
---|
theme | Eclipse |
---|
title | rename |
---|
|
letconst attach = new SimpleAttachment();
attach.rename('157052637119478714', 'new_name_1.png'); |
write(record, fileName, contentType, content)
This method inserts the attachment to the record specified.
Name | Type | Mandatory | Default Value |
---|
record | SimpleRecord | Y | N |
filename | String | Y | N |
contentType | String | Y | N |
content | String | Y | N |
Return
Type | Description |
---|
String | The attachment's sys ID. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | write |
---|
|
letconst attach = new SimpleAttachment();
letconst record = attach.write('157052637119478714', 'readme.md', 'text/markdown', '# h1 title'); |
writeBase64(documentId, fileName, base64, contentType)
This method inserts the attachment to the record specified using Base64 encoding.
Name | Type | Mandatory | Default Value |
---|
documentID | String | Y | N |
fileName | String | Y | N |
base64 | String | Y | N |
contentType | String | Y | N |
Return
Type | Description |
---|
String or NULL | The attachment's sys ID; in case of error; returns NULL. |
Example:
Code Block |
---|
language | js |
---|
theme | Eclipse |
---|
title | writeBase64 |
---|
linenumbers | true |
---|
|
|