
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 10:11 AM
Hi guys, is it possible to check if one of the fields was updated in Script Include ? im populate fields with script include rest api data, and i need to check if fields the same - do not update it
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2020 08:19 AM
Hi,
Since you have multiple record sys_ids you need to iterate over each record and check
Also if you want to check for multiple fields then you need to check them one by one and if not same then update
sample script below:
as.addQuery('id', 'IN', ids);
as.query();
while(as.next()){
for(var i=0;i<result.length;i++){
if(as.u_account_status != result[i].AccountStatus)
as.u_account_status = result[i].AccountStatus;
if(as.u_account_status_name != result[i].AccountStatusName)
as.u_account_status_name = result[i].AccountStatusName;
as.update();
}
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 10:14 AM
Hi,
please explain with some example
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2020 10:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2020 06:18 AM
Hi,
So you are consuming rest message of 3rd party.
If you only want to update record if any field has changed as compared to the response received you should be having some query on unique field and then compare the field value with the response field value then you can handle this
Example: Consider you want to compare short description received from REST Message against incident short description and update notes only when value is different
Sample Script:
var responseBody = '{"number":"INC001","short_description":"helloabc","notes":"notes123"}';
// parse the above json
var parser = JSON.parse(responseBody);
var responseInc = parser.number; // this gives INC001
var shortDescAfterParsingResponse = parser.short_description; // this gives helloabc
var inc = new GlideRecord('incident');
inc.addQuery('number', responseInc);
inc.query();
if(inc.next()){
if(inc.short_description != shortDescAfterParsingResponse){
// values are different so update notes
inc.notes = parser.notes;
inc.update();
}
}
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2020 08:07 AM