Need to auto approve RITMs if the requested_by is part of a certain group.

Logan Calhoun
Tera Expert

I have created a group that has all VIPs and Executives. When the a request is put in, with the requested_by being apart of that group, I need the RITM to auto approve. I have successfully done this in workflows but it would be very work intensive to have to go through each workflow and change them. My plan was to add a business rule to the RITM table but I have been unsuccessful in doing so.

 

Any help would be appreciated! 

7 REPLIES 7

Follow this structure: 

On the main record click advanced. 

Click on the When to Run tab: When = Before, check the box for Insert. 

find_real_file.png

Click on the Actions tab:

Select: State

Select:  To

Select: Approved

find_real_file.png

Click on the Advanced Tab

Enter the condition in the single-line text for condition at the top of that section: 

current.document_id.getRefRecord().sys_class_name == "sc_req_item" && gs.getUser().getUserByID(current.document_id.getRefRecord().requested_for).isMemberOf('Catalog Request VIPs')

find_real_file.png

No code goes in the Script section - just the condition. 

I hope this helps!

If this was helpful, or correct, please be kind and mark the answer appropriately.

Michael Jones - Proud member of the GlideFast Consulting Team!

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!

I finished the structure, so far it looks like:

find_real_file.png

When I fill out a request the RITM would not auto approve. I would also have to modify the condition for the "Requested By" instead of "Requested For" which I believe would have to be pulled from the variables on the RITM table. 

You're not using a Requested For variable type on your items? You might want to look into those going forward (they automatically set the Requested For on the RITM) but, if you have a variable on item named requested_by then try this condition. 

Checks if the approval is tied to a RITM. 

Gets the user record for the value stored in a variable named requested_by.

Checks if the user is a member of your group. 

current.document_id.getRefRecord().sys_class_name == "sc_req_item" && gs.getUser().getUserByID(current.document_id.getRefRecord().variables.requested_by).isMemberOf('Catalog Request VIPs')

You can test this to see if it will return true of false by creating a request with an approval you think should be auto approved (eventually) - go to the approval and get the sys_id, and then run this in a background script - if it returns true, then it should work (make sure you have the actions set on the BR to update the state). 

var sys_id = '0a8fc69107ad5110c5cff1e08c1ed0ec'; //sys_id of your approval
var current = new GlideRecord('sysapproval_approver');
current.get(sys_id);

var result = (current.document_id.getRefRecord().sys_class_name == "sc_req_item" && gs.getUser().getUserByID(current.document_id.getRefRecord().variables.requested_by).isMemberOf('Catalog Request VIPs'));

gs.info(result);

I hope this helps!

If this was helpful, or correct, please be kind and mark the answer appropriately.

Michael Jones - Proud member of the GlideFast Consulting Team!

 

I hope this helps!
Michael D. Jones
Proud member of the GlideFast Consulting Team!