Automation in workflow

sandeshraut198
Tera Contributor

For example, for UK customer, XYZ is the HR representative who approves all the "catalog item name", however he is usually also the one raising these requests herself.  Can we automate it somehow so that he would not have to approve her own request?

3 REPLIES 3

Dnyaneshwaree
Mega Sage

You can use below "IF" script before the approval action in the workflow:

answer = ifScript();

function ifScript(){
    var app = new GlideRecord('u_catalog_approval_rules');
    var user = current.request.requested_for.company;
    app.addQuery('u_company', user);
    app.query();
    if(app.next()){
        var grMember = new GlideRecord('sys_user_grmember');
        var openBy = current.request.opened_by;
        grMember.addQuery('group', app.u_approval_group);
        grMember.addQuery('user', openBy);
        grMember.query();
        if(grMember.next()){
            return 'no';
        } else {
            return 'yes';
        }
    }
}
Please accept my solution if it works for you and thumps up to mark it as helpful.
Thank you!!

Dnyaneshwaree Satpute
Tera Guru

Alp Utku
Mega Sage

You can refer to the below script to automatically approve the RITM when opened by and request for is the same person. You need to create If action on the workflow. Then when "yes" returns, you can create approval action in the workflow to approve the RITM automatically.

 

//Please double check the field names
var openedBy = current.request.opened_by;

var reqFor= current.request.request_for; 

answer = ifScript();

function ifScript() {

if (openedBy == reqFor) {

return 'yes';
     }
      return 'no';
  }

  

Sumanth16
Kilo Patron

Hi @sandeshraut198 ,

 

Business Rule #1

  • Table : Approval [sysapproval_approver]
  • When to run : before update

Sumanth16_0-1710281791906.png

 

Business Rule #2

  • Table : Change Request [change_request]
  • When to run : after insert/update

Sumanth16_1-1710281791905.png

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda