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
const attach = SimpleAttachmentServicenew SimpleAttachment();
const result = attach.setUrlbase64Decode('http://simple.testTG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=');
attachss.setUsernameinfo('admin'result);
attach.setPassword('123456');
const sysId = attach.createAttachmentByUrl('http://simple.test/v1/attachments/download/159229954513242397', '0229fa8a-bcbe-1f54-0229-fa8abcbe1f01', 'test.sop');// 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('157052637119478714Lorem ipsum dolor sit amet');
ss.info(result);
// Info: TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQ=

copy(

sourceTable

sourceTableName, sourceID,

targetTable

targetTableName, targetID)


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

Parameter(s):

NameTypeMandatoryDefault Value
sourceTablesourceTableNameStringYN
sourceIDStringYN
targetTabletargetTableNameStringYN
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', '155964310500000051');

createAttachmentByUrl(url, SimpleRecordId, fileName)

This method allows to get a file from remote instance by an URL provided.

Parameter(s):

NameTypeMandatoryDefault ValueurlStringYNSimpleRecordIdStringYNfileNameStringYN

Return:

TypeDescriptionString

Example:

Code Block
languagejs
themeEclipse
titlecreateAttachmentByUrl
linenumberstrue
let create = net SimpleAttachment();
create.copy('https://instance.simpleone.ru/')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 ATTACH_ID = '163553718313772587';
const simpleAttach = new SimpleAttachment();
const publicUrlattachUrl = attachsimpleAttach.getAttachmentUrlById('157052637119478714'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 DOC_ID = ss.getDocIdByIds(current.sys_db_table_id, current.sys_id);
const simpleAttachconst attach = new SimpleAttachment();
attach.rename('157052637119478714', 'new_name_1.png');
write(record, fileName, contentType, content
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 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 attachsimpleAttach = new SimpleAttachment();
const recordattachID =
   attach simpleAttach.write('157052637119478714', (
        ss.getDocIdByIds(current.sys_db_table_id, current.sys_id),
        'readme.mdjson',
     'text/markdown', '# h1 title'   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
collapsetrue
const writeconst CURRENT_USER_DOC_ID = ss.getDocIdByIds(ss.getUser().sys_db_table_id, ss.getUserID());
const simpleAttach = new SimpleAttachment();
const base64base64Value = 'iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAYAAABccqhmAAAABHNCSVQICAgIfAhkiAAABYFJREFUeJzt3SGQVVUcwOGLQyDSoGkDGyRpYnJIaFpIQDLiNrdh2jE5NE1Ic5smJaHRJLSlSdNGpGl2TOfIu+/xft+X75lzF977zQnvP+fMwt64uSx/b/sdtunHZTmz7Xd427yz7RcAtkcAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIMzwxErWGNQ5+fD+preY9+3g85+Nb3Hw68PhNfUBIicACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACDu77Rd4G80M9qwxqPPTn682vseyLMv7X5wOr3lvuTa24MlXw3ss58aHgeqcACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACAsfSnCssz9rv/upTvD+9y4eH7o+bV+1//pi8er7LNn9uZ74wQAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYQIAYXsz1LAs6w32rMGQzt7Zye+aEwCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCEnd32C2zbjZO7w2vOXfnozb/IG/D6/mfDa849/HYn95ncYycHbnaZEwCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCE7ezwxMwtPyfPng7v8/XxreE1h0ffD68ZHSCaGYZZ7o3/LTODTa8n/p2H//6V/i9nHJ38tbPfm1FOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABC2XzcDPRof0tlVUzf2TAwDzQzdzFhjn5khrTm3hgfVdnWAyAkAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwgQAwvZqFmDq9/MzF3CsYK3f6E9dDLKj/2aMcwKAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAMAGAsJ28rOB/GL6wYcYqwzATl3zMDPYwZW++N04AECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAECYAELY3Qw3/w/AA0fHBhU28x78cXvxk43vMmrmBaYelvwNOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABCWHoSYdXNigOjupTtDz59e+Xl0i532zennQ8+/fH7ks7kCJwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIyw9crDHYM+PGxfPDaz6+fnkDb/Jf129f3fge3x08HV5jgGicEwCECQCECQCECQCECQCECQCECQCECQCECQCECQCECQCEnd32C7yN1ri043Rq1YPhFU+O7k3tNOr4j2dDz7/47XB4j0sfjM911OcHnAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgTAAgLD8MdO3gwvCaw8cvN/Amb8CddycWrTMMxG5yAoAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYAwAYCw/DDQrvp6YrDn58sPxtccPxpeM+P67atDz4/eJMQcJwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIEwAIMwzEsD9+eDW85pfl943v8fL50ZnhRXFOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABBmeGLC8cGFv7f9Dm/K0clfw2uODy6ssY/P5gqcACBMACBMACBMACBMACBMACBMACBMACBMACBMACBMACDM763nDM8CzPx+fg2HX94aXnPu8sPhNa9P7298j8XneZgTAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQJAIQZnpizNxeD7Bmf50FOABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABAmABD2D4/fmKms6poKAAAAAElFTkSuQmCCR0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=';
const icoattachId = writesimpleAttach.writeBase64('mario.png', base64, 'image/png', '156819163902483433'
    CURRENT_USER_DOC_ID,
  	'file_example.gif',
    base64Value,
    'image/gif'
);
ss.info(icoattachId);
//Info: 162245472311776172


Table of Contents
absoluteUrltrue
classfixedPosition