How to create a json payload in script include ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 01:13 AM
Hello experts,
My requirement is to transfer the worknotes and additional comments to target instance whenever worknotes changes or additional comments changes in source instance.
I have used Ebonding.
But while creating payload i am not able to get the correct data in my payload:
Below is the script I am using:
var PayloadBuilderUpdate = Class.create();
PayloadBuilderUpdate.prototype = {
initialize: function() {
},
createIncidentPayloadUpdate:function(incident_sys_id){
var incidentSysId = incident_sys_id;
var incidentRec = new GlideRecord('incident');
//incidentRec.get(incidentSysId);
incidentRec.addQuery('sys_id',incidentSysId);
incidentRec.query();
while(incidentRec.next())
{
if(incidentRec.work_notes.changes())
{
var incidentValues = {};
incidentValues.work_notes =incidentRec.work_notes.getJournalEntry(1);
//comments: incidentRec.comments.getJournalEntry(1)
}
}
return incidentValues;
},
type: 'PayloadBuilderUpdate'
};
Can you please help here.
Thanks in advance!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 01:21 AM
can you declare outside the while loop
var incidentValues = {};
so you can retain the values stored.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 02:24 AM
Hello Anil,
I have tried this but it's giving empty value in response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 01:29 AM
Can you elaborate on where are you failing ?
Few things i noticed not that they are all wrong but need consideration
1. if you are passing direct sysid of incident in the function you dont need a while , it will always be one record
2. you are returning the object directly , convert to a string and then try , something like JSON.stringify(variable_name)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 02:28 AM
Hello Ravi ,
My issue is whenever I am changing work notes in one record in source instance same work notes are not getting copied through ebonding.
So earlier it was working fine with this script:
PayloadBuilderUpdate.prototype = {
initialize: function() {
},
createIncidentPayloadUpdate:function(incident_sys_id){
var incidentSysId = incident_sys_id;
var incidentRec = new GlideRecord('incident');
incidentRec.get(incidentSysId);
var incidentValues = {
work_notes: incidentRec.work_notes.getJournalEntry(1)
//comments: incidentRec.comments.getJournalEntry(1)
};
return incidentValues;
},
type: 'PayloadBuilderUpdate'
};
But since my requirement is to copy only worknotes when work notes are added and copy only additional comments when additional comments are added ,through above script when either of worknotes or additional comments are added it was copying both work notes and additional comments.
That's why i though to add if condition and added the condition of work_notes.changes() but it is now not copying the worknotes as well.
Also the points which you have highlighted are taken care of , still it's not working.