You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

This server class provides methods that allow operating the attachments.

SimpleAttachment()


Instantiates a new empty SimpleAttachment object.


SimpleAttachment
const attach = new SimpleAttachment();


base64Decode(data)


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


Parameter(s):

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringA decoded string.

Example:

base64Decode
const attach = new SimpleAttachment();
const result =
  attach.base64Decode('TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=');
ss.info(result);

base64Encode(data)


This method returns a Base64 string from the string specified.


Parameter(s):

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringAn encoded Base64 string.

Example:

base64Encode
const attach = new SimpleAttachment();
const result =
  attach.base64Encode('Lorem ipsum dolor sit amet');
ss.info(result);

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
BooleanThis method returns 'true' if attachments have been copied successfully; otherwise, it returns 'false'.


Example:

copy
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:

deleteAttachment
const attach = new SimpleAttachment();
attach.deleteAttachment('157052637119478714');

getAttachmentUrlById(attachmentId)


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


Parameter(s):

NameTypeMandatoryDefault Value
attachmentIdstringYN


Return:

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

Example:

getAttachmentUrlById
const current = new SimpleRecord('sys_attachment');
current.get('163553718313772587');
const ATTACH_ID = current.sys_id;

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 the attached content as a string.

Parameter(s):

NameTypeMandatoryDefault Value
sysAttachmentSimpleRecordYN

Return:

TypeDescription
StringThe attachment content as a string.

Example)

getContent
const attach = new SimpleAttachment();
const content = attach.getContent('157052637119478714');

readBase64(attachmentId)


This method allows getting an encoded string from the specified attachment.

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
StringA base64-encoded string.
readBase64
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:

rename
const DOC_ID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id);
const simpleAttach = new SimpleAttachment();
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 an attachment to the record specified.

Parameter(s):

NameTypeMandatoryDefault Value
documentIdStringYN
filenameStringYN
contentStringYN
contentTypeStringYN

Return

TypeDescription
StringThe sys_ID of the attachment; in case of an error, it returns NULL.

Example:

write
const simpleAttach = new SimpleAttachment();
const attachID =
    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)


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

Parameter(s):

NameTypeMandatoryDefault Value
documentIDStringYN
fileNameStringYN
base64StringYN
contentTypeStringYN

Return

TypeDescription
String or NULLThe sys_ID of the attachment; in case of an error, it returns NULL.

Example:

writeBase64
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

  • No labels