"packages" is not defined error in logs, var baos = new packages.java.io.ByteArrayOutputStream();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 04:44 AM - edited 09-01-2023 04:01 AM
Hi,
I'm trying to integrate two ServiceNow instances.
Goal: If I create an incident along with attachment in the instance A that should replicate the record & attachments in the instance B. For that I have written one Async - insert BR. If I try to create a record I'm getting - "packages" is not defined error in logs. I'm pasting the code here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:14 AM
don't use packages call if you are in scoped app
basically you want to get base64encoded data so use this for scoped app
(function executeRule(current, previous /*null when async*/ ) {
try {
var encodedFile;
var fileName;
var contentType;
var att = new GlideRecord("sys_attachment");
att.addQuery('table_name', current.getTableName());
gs.info('my table name' + current.getTableName());
gs.info('table name is :' + ' ' + current.getTableName());
att.addQuery('table_sys_id', current.sys_id);
att.query();
if (att.next()) {
var sysAtt = new GlideSysAttachment();
encodedFile = sysAtt.getContentBase64(att);
fileName = att.file_name;
contentType = att.content_type;
}
var r = new sn_ws.RESTMessageV2('demo_instanceA', 'incident_insert');
r.setStringParameterNoEscape('short_description', current.short_description);
r.setStringParameterNoEscape('correlation_id', current.number);
r.setStringParameterNoEscape('description', current.description);
r.setStringParameterNoEscape('encodedStr', encodedFile);
r.setStringParameterNoEscape('fileName', fileName);
r.setStringParameterNoEscape('fileType', contentType);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
} catch (ex) {
var message = ex.message;
gs.info('my error' + message);
}
})(current, previous);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 07:05 AM
Thanks for your time. I couldn't be able to reply from @chitturiamala account. I have followed the code which you have given. Record is getting created in the instance B but attachments are not getting copied. I have tried to capture the logs for "encodedFile" I'm getting it as undefined.
Here I'm posting my transform map script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:41 AM
Thanks for your time.
I can able to create a record in instanceB & attachment details are populating in the transform map table but it is not attaching to the incident record. Here is my onafter transform map script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 09:20 PM
are you in scoped app or global scope?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader