How to change Approval State after creation of Manual Approver in RITM

Lkowalski
Tera Contributor

Hello All!

 

I am looking for solution for my below script in Business rule.

I am trying to make an automation of changing Approval State from "Approved" to "Requested" in RITM when Manual Approver in RITM has been created and set as "Requested" in sysapproval approver table.

 

In WF there is a set value action to make Approval=Approved after RITM creation.

 

Currently it is not working properly.

 

Lkowalski_0-1699957222478.png

 

 

 

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

    // Add your code here
    var gr = new GlideRecord("sysapproval_approver");
    gr.addQuery("sysapproval", current.request_item);
    gr.addQuery("sysapproval", current.sys_id);
    gr.addQuery("state", "approved");
    gr.query();
    if (current.approval == 'approved' && sysapproval_approver == 'requested') {
    current.approval == 'requested'; //Approval in RITM
} else
    current.approval == 'approved'; /Approval in RITM

})(current, previous);

 

 

 
Thank you in advance for any help.
 
Lukas
1 ACCEPTED SOLUTION

@Lkowalski  

Your Business rule was defined as after BR soo here you have to add a logic in your script .

var gr = new GlideRecord("sysapproval_approver");
	gr.addQuery("sysapproval", current.sys_id);
	gr.addQuery("state", "requested");
	gr.query();
    if (gr.next()) {
	current.approval = 'requested';
       current.update(); // this is not recommendated in after BR
} else
    current.approval = 'approved';
   current.update(); // this is not recommendated in after BR



View solution in original post

4 REPLIES 4

Anand Kumar P
Giga Patron

Hi @Lkowalski ,

Change the assignment to single equal sign for assignment.

 

 

  if (gr.next()) {
        current.approval = 'requested';
    } else {
        current.approval = 'approved';
    }

 

 

Please mark it as helpful and solution proposed if it serves your purpose.

Thanks,

Anand

 

Hi Anand,

I changed my script but it still not works.

 

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

	// Add your code here
	var gr = new GlideRecord("sysapproval_approver");
	gr.addQuery("sysapproval", current.request_item);
	gr.addQuery("sysapproval", current.sys_id);
	gr.addQuery("state", "approved");
	gr.query();
    if (gr.next()) {
	current.approval = 'requested';
} else
    current.approval = 'approved';

})(current, previous);

@Lkowalski  

Your Business rule was defined as after BR soo here you have to add a logic in your script .

var gr = new GlideRecord("sysapproval_approver");
	gr.addQuery("sysapproval", current.sys_id);
	gr.addQuery("state", "requested");
	gr.query();
    if (gr.next()) {
	current.approval = 'requested';
       current.update(); // this is not recommendated in after BR
} else
    current.approval = 'approved';
   current.update(); // this is not recommendated in after BR



Now it is working properly :).

I had also needed to remove Approval=Approved from filter condition.

Thank you for support! 🙂