How to create a json payload in script include ?

Mahak2
Kilo Guru

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.

@Ankur Bawiskar @Ashutosh Munot 

Thanks in advance!!

10 REPLIES 10

Ravi9
ServiceNow Employee
ServiceNow Employee

Hi Mahak

I think its better if you provide most of the information at one go , its confusing 🙂

Based on what you have shared at the moment - here is my suggestion -  This link shows how to use flow api - which means you can pass input parameters dynamically - so hypothetically you can pass field name and values to the flow and make flow such that it takes action based on inputs

See if this works out or too much ATM