Thursday 13 June 2024

Servicenow attachment

 


servicenow glidesystattache(mostly scoped, delete can be used as global)


delete to be used as global:

https://www.servicenow.com/community/developer-forum/remove-attachments-using-glidesysattachment/m-p/1919541

https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/GlideSysAttachmentGlobalAPI#GSA-deleteAttachment_S?navFilter=attach


        var gr = new GlideRecord(table_name);

        gr.addQuery('sys_id', table_rec_sys_id);

        gr.query();

        if (gr.next()) {

            var attach = new GlideSysAttachment();

            attach.deleteAll(gr);

        }


scoped:

https://developer.servicenow.com/dev.do#!/reference/api/utah/server_legacy/GlideSysAttachmentGlobalAPI?navFilter=attach


servicenow string util (global scoped)

https://developer.servicenow.com/dev.do#!/reference/api/washingtondc/server/no-namespace/GlideStringUtilScopedAPI#GSUS-isBase64_S

*************************************************************************************************************************************


Servicenow global create attachment using binary(*might not always work):


script include reference  global.Attachment


https://www.servicenow.com/community/developer-forum/decoding-base64-encoded-file-and-writing-it-to-sys-attachment/m-p/2122987



var StringUtil = new GlideStringUtil();

var attachment = new Attachment();

if (JSUtil.notNil(source.u_attachment1_name))

attachment.write('incident',target.sys_id, source.u_attachment1_name, '', StringUtil.base64DecodeAsBytes(source.u_attachment1));

********************************************************************************************************************************************

Servicenow global scope use base64 to create attachment

https://www.servicenow.com/community/developer-forum/how-can-i-create-an-attachment-from-script/m-p/1443004/page/2

ecc queue create attachment, uses for base64


**********for servicenow, might need to use ur own base64tobin(), combinebin(), bintobase64() ********** refer to 

org.mozilla.javascript.NativeArray to byte


 The error message "can't convert org.mozilla.javascript.NativeArray to byte" typically occurs when working with JavaScript in environments that use the Rhino engine or similar JavaScript interpreters in Java contexts, such as ServiceNow's scripting environment. This environment may not directly support certain JavaScript data types or operations as expected in a standard browser-based JavaScript engine.


Here’s how to handle and convert JavaScript arrays to binary data without encountering such errors, specifically for environments like ServiceNow.


***********************************

var eccGr = new GlideRecord('ecc_queue');



eccGr.initialize();



eccGr.setValue('agent', 'AttachmentCreator');



eccGr.setValue('topic', 'AttachmentCreator');



eccGr.setValue('name', fileName+':'+contentType);



eccGr.setValue('source', tableName+':'+tableSysId);



eccGr.setValue('payload', content);


No comments:

Post a Comment