
- 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-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-21-2020 08:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2020 08:26 AM
Small correction in script; it should be like this
First use for loop for json object and for each for loop query the target record with that result ID and then inside the while check for fields
for(var i=0;i<result.length;i++){
var as = new GlideRecord('table');
as.addQuery('id', result[j].ID.toString());
as.query();
while(as.next()){
if(as.u_account_status != result[j].AccountStatus)
as.u_account_status = result[j].AccountStatus;
if(as.u_account_status_name != result[j].AccountStatusName)
as.u_account_status_name = result[j].AccountStatusName;
as.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:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2020 09:42 AM
Hi,
i believe iterating over the json would be easier since you can query with the particular request ID in the addQuery with the request ID
If you iterate over using addQuery('id','IN', ids)
then it would be difficult to keep track of which result ID you need to use for value comparison
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader