How to check all approvals are approved & set incident state to inprogress?

Banu1
Mega Expert

Hi All,

Please help me with How to check all approvals are 'approved' & set incident state to in-progress ? and if any one approval is in 'requested' state then incident state should be in 'pending'.

Once Approver is added or any approval is in requested state then — Incident Status is change to 'Pending Approval' and If approval is rejected or approved incident is changed to 'in progress' status.

// tried gliding both approver table & incident table but not working as per expected.

  var number = current.sys_id;

  var gr = new GlideRecord("sysapproval_approver");

  gr.addQuery("sysapproval", number);

  gr.query();

  while(gr.next()) {

  var st = gr.state;

  if(st == 'approved' || st =='rejected'){

  current.state = 2;   //in progress

  current.update();

  }

  if(st =='requested') {

  current.state = 3;   // pending

  current.update();

  }}

Thank You.

10 REPLIES 10

abhishekdash
ServiceNow Employee
ServiceNow Employee

Hello Banupriya,



See if below thread helps:



How to check whether all the approvals are completed ?



Thanks,


Abhishek



If this reply assisted you, please consider marking it Correct, Helpful, or Like it.


This helps other customers to learn from your thread.


Harsh Vardhan
Giga Patron

why don't you use condition for approval in the approval activity. once all will approve then use set value activity and make the incident state in-progress.



find_real_file.png



Approval - User workflow activity


no workflow for Incident management.


are you able to access "st" variable in if condition. can you please use log




var st ='';


var number = current.sys_id;


  var gr = new GlideRecord("sysapproval_approver");


  gr.addQuery("sysapproval", number);


  gr.query();


  while(gr.next()) {


  st= gr.state;


  if(st == 'approved' || st =='rejected'){


  current.state = 2;   //in progress


  current.update();


  }


gs.log('value is:'+st);


  if(st =='requested') {


  current.state = 3;   // pending


  current.update();


  }