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
languagejs
themeEclipse
titleSimpleAttachment
linenumberstrue
const attach = new SimpleAttachment();


base64Decode(data)


This method returns an ASCII string decoded from the base64 string specified.

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringThe decoded string.

Example:

Code Block
languagejs
themeEclipse
titlebase64Decode
linenumberstrue
collapsetrue
const attach = new SimpleAttachment();
attach.base64Decode('TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdCwgc2VkIGRvIGVpdXNtb2QgdGVtcG9yIGluY2lkaWR1bnQgdXQgbGFib3JlIGV0IGRvbG9yZSBtYWduYSBhbGlxdWEuIA==');
let result = attach.base64Decode;


base64Encode(data)


This method returns a Base64 string from the string specified.

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringThe encoded Base64 string.

Example:

Code Block
languagejs
themeEclipse
titlebase64Encode
linenumberstrue
collapsetrue
const attach = new SimpleAttachment();
attach.base64Encode('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.');
let result = attach.base64Encode;

copy(sourceTable, sourceID, targetTable, targetID)


This method copies attachments from the source record to the target record.

Parameter(s):

NameTypeMandatoryDefault Value
sourceTableStringYN
sourceIDStringYN
targetTableStringYN
targetIDStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlecopy
linenumberstrue
const attach = new SimpleAttachment();
attach.copy('sys_email', '155964310500000059', 'task', '155964310500000051');

deleteAttachment(attachmentID)


This method deletes the specified attachment.


Parameter(s):

NameTypeMandatoryDefault Value
attachmentIDStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titledeleteAttachment
const attach = new SimpleAttachment();
attach.deleteAttachment('157052637119478714');

getAttachmentUrlById(attachmentId)


This method allows to get the URL of the specified attachment at the cloud storage.


NameTypeMandatoryDefault Value
attachmentIdstringYN


Return:

TypeDescription
StringThis method returns the attachment URL in the cloud storage.

Example:

Code Block
languagejs
themeEclipse
titlegetCloudStorageUrl
linenumberstrue
const attach = new SimpleAttachment();
const publicUrl = attach.getAttachmentUrlById('157052637119478714');
ss.info(publicUrl);

getContent(sysAttachment)


This method gets attachment content as a string.

NameTypeMandatoryDefault Value
sysAttachmentSimpleRecordYN


Return:

TypeDescription
StringThe attachment content as a string.


Example)

Code Block
languagejs
themeEclipse
titlegetContent
linenumberstrue
const attach = new SimpleAttachment();
const 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):

NameTypeMandatoryDefault value
attachmentIdStringYN


Return:

TypeDescription
StringThe base64-encoded string.


Code Block
languagejs
themeEclipse
titlereadBase64
linenumberstrue
const read = new SimpleAttachment();
ss.info(read.readBase64('159050716911764097'));

rename(attachmentId, fileName)


This method renames the specified attachment.


Parameter(s):

NameTypeMandatoryDefault Value
attachmentIdStringYN
fileNameStringYN


Return:

TypeDescription
VoidThis method does not return a value.


Example:

Code Block
languagejs
themeEclipse
titlerename
linenumberstrue
const attach = new SimpleAttachment();
attach.rename('157052637119478714', 'new_name_1.png');

write(

record

documentId, fileName, content, contentType

, content

)


This method inserts the attachment to the record specified.

contentType
NameTypeMandatoryDefault Value
recorddocumentIdSimpleRecordStringYN
filenameStringYN
contentStringYN
contentcontentTypeStringYN


Return

TypeDescription
StringThe attachment's sys ID; in case of error; returns NULL.

Example:

Code Block
languagejs
themeEclipse
titlewrite
linenumberstrue
const attach = new SimpleAttachment();
const recordattachID =
  attach.write('157052637119478714', 
    ss.getDocIdByIds(current.sys_db_table_id, current.sys_id),
    'readme.md', 'text/markdown', '# h1 title'json',
    JSON.stringify(current.getAttributes(), null, "\t"),
    'application/json'
  );

writeBase64(documentId, fileName, base64, contentType)


This method inserts the attachment to the record specified using Base64 encoding.

NameTypeMandatoryDefault Value
documentIDStringYN
fileNameStringYN
base64StringYN
contentTypeStringYN


Return

TypeDescription
String or NULLThe attachment's sys ID; in case of error; returns NULL.

Example:

Code Block
languagejs
themeEclipse
titlewriteBase64
linenumberstrue
const write = new SimpleAttachment();
const base64 = request.execute().getBody(); // base64 string
const attachId =
  attach.writeBase64(
    ss.getDocIdByIds('157045360815629732', '155964310500006867'),
    'watch.xlsx',
    base64,
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
  );
ss.info(attachId);


Table of Contents
absoluteUrltrue
classfixedPosition