Client Script

ARAVIND22
Tera Contributor

@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

 

 

2 ACCEPTED SOLUTIONS

praneeth7
Tera Guru

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.

View solution in original post

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.

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@ARAVIND22 

so what script did you start with?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@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();
}
}
}

 

@ARAVIND22 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

praneeth7
Tera Guru

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.