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

Not tried with gs log. will try it.. can you suggest me is there any other way to achieve this?


I kept gs log & its getting the value. my problem is when I ADD approves for example if I add 2 approves incident state changes to 'pending' that's correct. If one s approved & other one is still in requested state then Incident state is in 'pending' this is also correct. When i approve both then Incident state is in 'in progress' this is also correct. Again if suppose I add a approver it's not seting the incident state as 'pending' instead it's in 'in progress' only.   If you have any suggestions plz let me know. Is there any other way to check this ?


Hi



Updated script:




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;


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


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


gs.log('first it');


  current.state = 2;   //in progress


    }


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


  if(st =='requested') {


gs.log('second if');


  current.state = 3;   // pending


  }


  current.update();


}




try and let me know if it does not help


Hi thank you for the script. still the same issue. it works for only first time. if i approved all the approvers & added again a approver it is still in 'in -progress' state.


I hope need to check the number of rows in approval has the status as approved/rejected & then to set incident status as inprogress. trying it out. if you suggest anything else let me know. ty.