Auto Populate Approver

BheemavarapuTej
Tera Expert
Sent by you:
In the Change Request table approver approval the change Approver is auto Populate description in service now how to achieve this?
Table Name: Change Request
 
After Business rule
record update time execution
 
 
 

  var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
    gr.orderBy('approver');
    gr.query();
    if (gr.next()) {
        current.setValue('description', gr.sys_id);
    }

 

 

1 ACCEPTED SOLUTION

I have found the answer to this question.

table name is

sysapproval_approver

 

 
  1.     var gr = new GlideRecord('change_request');
  2.     gr.addQuery('sys_id', current.sysapproval.sys_id);
  3.     gr.addQuery('assigned_toISEMPTY^state=-4');
  4.     gr.query();
  5.     if (gr.next()) {
  6.         gr.assigned_to = current.approver.toString();
  7.         gr.update();
  8.     }
  9.  

View solution in original post

3 REPLIES 3

saivenkates5338
Tera Contributor

Hi @BheemavarapuTej 

After insert --- update 

 

You can try the below script :

(function executeRule(current, previous /*null when async*/) {
    var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
	gr.addQuery('state','approved'); 
    gr.query();

    var approverList = [];
    while (gr.next()) {
        approverList.push(gr.getDisplayValue('approver')); 
    }

    if (approverList.length > 0) {
        var approvers = approverList.join(', '); 
        current.setValue('description', 'Approvers: ' + approvers);
        current.update(); 
    }
})(current, previous);

 

Thanks and Regards

Sai Venkatesh

 

 

SAI VENKATESH
Tera Sage
Tera Sage

Hi @BheemavarapuTej 

 

You can try the below script :

 

after ----update 

 

(function executeRule(current, previous /*null when async*/) {
    var gr = new GlideRecord('sysapproval_approver');
    gr.addQuery('sysapproval', current.sys_id);
	gr.addQuery('state','approved'); 
    gr.query();

    var approverList = [];
    while (gr.next()) {
        approverList.push(gr.getDisplayValue('approver')); 
    }

    if (approverList.length > 0) {
        var approvers = approverList.join(', '); 
        current.setValue('description', 'Approvers: ' + approvers);
        current.update(); 
    }
})(current, previous);

 

 

Thanks and Regards

Sai Venkatesh

 

 

I have found the answer to this question.

table name is

sysapproval_approver

 

 
  1.     var gr = new GlideRecord('change_request');
  2.     gr.addQuery('sys_id', current.sysapproval.sys_id);
  3.     gr.addQuery('assigned_toISEMPTY^state=-4');
  4.     gr.query();
  5.     if (gr.next()) {
  6.         gr.assigned_to = current.approver.toString();
  7.         gr.update();
  8.     }
  9.