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

Compare with Current View Page History

« Previous Version 49 Next »

This server class provides methods that allow operating with 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.

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringThe 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.

NameTypeMandatoryDefault Value
dataStringYN


Return:

TypeDescription
StringThe 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 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 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:

getCloudStorageUrl
const attach = new SimpleAttachment();
const attachID = current.sys_id; // sys_attachment sys_id
const attachment = new SimpleRecord('sys_attachment');
attachment.get(attachID);
attachment.is_public = '1';
attachment.update();
const publicUrl = attach.getAttachmentUrlById(attachID);
print(publicUrl);

getContent(sysAttachment)


This method gets attachment content as a string.

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 to get a encoded string from the specified attachment.

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

write
const attach = new SimpleAttachment();
const attachID =
  attach.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 Base64 encoding.

NameTypeMandatoryDefault Value
documentIDStringYN
fileNameStringYN
base64StringYN
contentTypeStringYN

Return

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

Example:

writeBase64
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);

  • No labels