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 03:01 AM
Hi Mahak,
The line incidentRec.work_notes.changes() will not work as you are gliding into table again and verifying if value is getting changed.
Your script is not efficiently written, please use below approach and script.
Script Include :
var PayloadBuilderUpdate = Class.create();
PayloadBuilderUpdate.prototype = {
initialize: function() {
},
createIncidentPayloadUpdate:function(current,changedFieldName){
var incidentValues = {};
if(changedFieldName=="work_notes"){
incidentValues.work_notes =current.work_notes.getJournalEntry(1);
}
else if(changedFieldName=="comments"){
incidentValues.additional_notes=current.additional_notes.getJournalEntry(1);
}
else{
incidentValues.additional_notes=current.work_notes.getJournalEntry(1);
incidentValues.work_notes =current.additional_notes.getJournalEntry(1);
}
}
Business Rule :
Business Rule script:
Also make sure that you change field names depending on your field names.
Let me know if you have any further queries.
Please mark this as Correct or Helpful if it helps.
Thanks and Regards,
Abhijit
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 03:42 AM
Hello Abhijit,
Thanks for your reply.
Actually I am using flow designer to trigger the process of copying work notes and comments.
And in flow designer I have created some actions using out of the ebonding actions. I have called script include in that action.
There is one action update remote incident which is copying different fields , i have created copy of that action and i am only copying work notes at present .
But as per my requirement I want to copy both work notes and additional comments as per the changes in individual fields.
So how can i proceed with that approach.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 03:44 AM
I know I can create another copy of that action and call different script include there which contains only additional comments but it would require creation of separate flow , action and script include . I was thinking if there is a way to collaborate everything in one .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 04:33 AM
and what is the trigger point for the flow?
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2022 05:34 AM
The trigger point is if work notes changes or additional comments changes and updated by is not integration user.