Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Merged branch "DOC0000926" into parent

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();
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.

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringThe encoded Base64 string.

Example:

Code Block
languagejs
themeEclipse
titlebase64Encode
linenumberstrue
const attach = new SimpleAttachment();
const result =
  attach.base64Encode('Lorem ipsum dolor sit amet');
ss.info(result);
// Info: TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=

copy(sourceTableName, sourceID, targetTableName, targetID)


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

Parameter(s):

NameTypeMandatoryDefault Value
sourceTableNameStringYN
sourceIDStringYN
targetTableNameStringYN
targetIDStringYN


Return:

TypeDescription
VoidBooleanThis method does not return a valuereturns TRUE if attachments copied successfully; otherwise, it returns FALSE.


Example:

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

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
titlegetCloudStorageUrlgetAttachmentUrlById
linenumberstrue
const attach = new SimpleAttachment();
const attachID ATTACH_ID = '157052637119478714163553718313772587';
const attachmentsimpleAttach = new SimpleRecordSimpleAttachment('sys_attachment');
attachment.get(attachID);
attachment.is_public = '1';
attachment.update();
const publicUrlattachUrl = attachsimpleAttach.getAttachmentUrlById(ATTACH_ID);
ss.info(publicUrl);attachUrl);
// Info: https://s3-{your-instance-url}/public-attachment/5/32/9bnc2pcb3axyfatgtc6lsi7...

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 = ss.info(attach.getContent('157052637119478714168109939701169218'));
// 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: File size exceeded allowed limit.


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('159050716911764097168025458107121347'));
// Info: 0YLQtdGB0YLQvtCy0YvQuSDQtNC+0LrRg9C80LXQvdGC

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 attachconst DOC_ID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id);
const simpleAttach = new SimpleAttachment();
const attachmentRecordattachRecord = new SimpleRecord('sys_attachment');
attachmentRecordattachRecord.addQuery('record_document_id', ss.getDocIdByIds(current.sys_db_table_id, current.sys_id));
attachmentRecordDOC_ID);
attachRecord.addQuery('mime_content_type', 'application/json');
attachmentRecordattachRecord.selectAttributes('sys_id');
attachmentRecordattachRecord.query();
attachmentRecordattachRecord.next();
attachsimpleAttach.rename(attachmentRecordattachRecord.sys_id, `${current.number}: updated at- ${new SimpleDateTime().getValue()current.subject}.json`);

write(documentId, fileName, content, contentType)


This method inserts the attachment to the record specified.

NameTypeMandatoryDefault Value
documentIdStringYN
filenameStringYN
contentStringYN
contentTypeStringYN


Return

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

Example:

Code Block
languagejs
themeEclipse
titlewrite
linenumberstrue
const attachsimpleAttach = new SimpleAttachment();
const attachID =
   attach simpleAttach.write(
        ss.getDocIdByIds(current.sys_db_table_id, current.sys_id),
        'readme.json',
        JSON.stringify(current.getAttributes(), null, '\t'),
        'application/json'
    );

writeBase64(documentId, fileName, base64,

contentType

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.

NameTypeMandatoryDefault Value
documentIDStringYN
fileNameStringYN
base64StringYN
contentTypemimeContentTypeStringYN


Return

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

Example:

Code Block
languagejs
themeEclipse
titlewriteBase64
linenumberstrue
const writeCURRENT_USER_DOC_ID = new SimpleAttachment()ss.getDocIdByIds(ss.getUser().sys_db_table_id, ss.getUserID());
const base64simpleAttach = new request.executeSimpleAttachment().getBody();
const base64Value = 'R0lGODlhAQABAIAAAP// base64 string/wAAACwAAAAAAQABAAACAkQBADs=';
const attachId =
  attachsimpleAttach.writeBase64(
    ss.getDocIdByIds('157045360815629732', '155964310500006867'),CURRENT_USER_DOC_ID,
    'watch.xlsx	'file_example.gif',
     base64 base64Value,
    'application/vnd.openxmlformats-officedocument.spreadsheetml.sheetimage/gif'
  );
ss.info(attachId);
//Info: 162245472311776172


Table of Contents
absoluteUrltrue
classfixedPosition