- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:03 PM - edited 02-17-2023 02:11 AM
@Ankur Bawiskar/friends, Sir please help
I need to Update the State in RITM which is showing as what ever the value is showing below I have to make it to closed complete - state. When the stage is complete
1- work in progress
2 - pending
3 - Open
PLEASE HELP VERIFY IMAGE ATTACHED AS WELL
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:55 PM
Hi Aravind,
This script will do the work. Just try to run it in Background-script
var item = new GlideRecord('sc_req_item'); item.addActiveQuery(); item.query(); while(item.next()){ var label = item.getDisplayValue('stage'); if(label == 'Completed'){ var value = item.getValue('state'); if(value == 1 || value== 2 || value == -5){ item.setValue('state',3); gs.print(value); item.update(); } } } |
Please mark my answer as helpful or solution if this helps you,
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 10:40 PM - edited 02-16-2023 10:43 PM
Hi Aravind,
1, 2, & -5 refers to the backend value of the state choices. You can find the values under configure dictionary or show choice list by right clicking on the field label.
If you find my answer useful, please mark my answer Helpful !!
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:50 PM
so what script did you start with?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 12:39 AM
@Ankur Bawiskar Can you help this with encoded query instead of while loop
var item = new GlideRecord('sc_req_item');
item.addActiveQuery();
item.query();
while(item.next()){
var label = item.getDisplayValue('stage');
if(label == 'Completed'){
var value = item.getValue('state');
if(value == 1 || value== 2 || value == -5){
item.setValue('state',3);
gs.print(value);
item.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-17-2023 02:19 AM
you can form it on table list using filter conditions
var encodedQuery = 'stage=complete^stateIN-5,1,2';
You can also use updateMultiple() for fast update
var item = new GlideRecord('sc_req_item');
item.addEncodedQuery('stage=complete^stateIN-5,1,2');
item.addActiveQuery();
item.query();
item.setValue('state',3);
item.updateMultiple();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2023 09:55 PM
Hi Aravind,
This script will do the work. Just try to run it in Background-script
var item = new GlideRecord('sc_req_item'); item.addActiveQuery(); item.query(); while(item.next()){ var label = item.getDisplayValue('stage'); if(label == 'Completed'){ var value = item.getValue('state'); if(value == 1 || value== 2 || value == -5){ item.setValue('state',3); gs.print(value); item.update(); } } } |
Please mark my answer as helpful or solution if this helps you,
Thank you.