Create JSON To be sent in Payload
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2023 01:49 AM - edited ‎04-14-2023 01:53 AM
Hi,
We need to send details of updated fields from an Incident form to 3rd party application.
For this, I have created a mapping table and have defined my source fields( which will be from ServiceNow) and Target fields which is of String Type.
Now, I need to trigger Rest call from a Business rule, and have written the script below:
This BR is written on the Incident table
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var getIncidentFields = new GlideRecord('Custom table Name');
getIncidentFields.addQuery('active', true);
getIncidentFields.query();
while (getIncidentFields.next()) {
if (current[getIncidentFields.source_attribute] != previous[getIncidentFields.source_attribute]) {
var obj = {};
gs.addInfoMessage('1 Value of JSON OBject is '+ current[getIncidentFields.source_attribute]);
obj[getIncidentFields.target_attribute]= current[getIncidentFields.source_attribute];
gs.addInfoMessage('Field ' + getIncidentFields['source_attribute'] + '.' + getIncidentFields.source_attribute + ' has changed!');
gs.addInfoMessage('Value of JSON OBject is '+ JSON.stringify(obj));
}
}
})(current, previous);
Problem with my script is I am not able to Form the JSON object and is coming as blank. I need to form a JSON object here. Can someone please assist.
Regards,
Surbhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-14-2023 02:03 AM
@Surbhi Srivasta it seems issue would with your if condition
if (current[getIncidentFields.source_attribute] != previous[getIncidentFields.source_attribute])
I will suggest you to use current.key... instead of using current[] to fetch value, and make sure these condition are giving you true value so it can go inside the if statement.
Hope this will help you.