how to auto populate choice field value on when change state is moved from one to another state

Payal2
Kilo Contributor

Need to set value of choice list field which is present on change task when change request is change .

when change move from one state to another .set choice field value in change task .

Example:

if change task has choice field "abc" with value as 1,2,3. also change state is in authorized state  and task choice field abc  value is 2.when change is moved from authorized to schedule state "abc" value should switch from 2 to 1.

How to implement this scenario.

1 ACCEPTED SOLUTION

Hi,

BR should be on change_request table

Condition:

State [Changes From] Authorized

AND

State [Changes To] Scheduled

Script:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

var chgTask = new GlideRecord('change_task');
chgTask.addQuery('change_request', current.sys_id);
chgTask.query();
while(chgTask.next()){
chgTask.u_confirmation = 'released';
chgTask.update();
}

})(current, previous);

Regards
Ankur

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

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

you can use after update BR on change_request table and update the change_task fields

Regards
Ankur

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

I have tried using after business rule but could not achieve this do i need to glide

 

Hi,

please share the script you tried

Regards
Ankur

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

Hi 

As my requirement is when change is moved from authorized to scheduled state.  on change task confirmation field value also changes from confirmed to released.

---------------------------------------------------------------------------------------------------

Previous i have tried after update business rule of change_task table

Filter condition: change.request.state changes from authroized.

confirmation is confirmed

Script: current.u_confirmation = 'released'.

but this was not working as in after update BR changeto and changefrom condition are not working.

---------------------------------------------------------------------------------------------------

 now I have written Before update Business rule 

Filter condition: state changes from authorize.

Script:

(function executeRule(current, previous /*null when async*/ ) {

var grChgtask = new GlideRecord('change_task');
grChgtask.addQuery('u_confirmation', 'confirmed');
grChgtask.query();
while (grChgtask.next()) {
grChgtask.u_confirmation = 'released';
grChgtask.update();
}

 

i am not sure what business rule will be used  or i need to handle using script include?