Move custom field value in ritm to approvers

LuLe Game
Tera Expert

Hello everyone
I need your help with the sysapproval_approver table. First I have a ritm (catalog item), and in this ritm I have a custom field (text field for comments). I would like to pass the value of this custom field to the comments field (highlated below) of the approvers through a Business Rule. But the script, and I have tried multiple ones, none have worked. Can anyone tell me if it can be achieved with a script or does it need to be done in a different way?

 

Capture1.JPG

6 REPLIES 6

AnveshKumar M
Tera Sage
Tera Sage

Hi @LuLe Game 

You have the comments field as a Catalog Item variable OR a field on sc_req_item table?

 

If it's on catalog item as a variable, try this in a Before Insert BR on sysapproval_approver table.

 

In When to Run Section, select the conditions so that, the BR runs only for that specific Catalog Item  (dot walk using show related fields in condition builder).

 

Screenshot_2024-01-04-07-52-07-281-edit_com.android.chrome.jpg

 

(function executeRule(current, previous){

var ritm = current.sysapproval;

var comments= ritm.variables.comments; //replace with your variable name

current.comments = comments;

 

}(current, previous);

 

If the field is at RITM table level, just change the script to the following one.

 

(function executeRule(current, previous){

var ritm = current.sysapproval;

var comments= ritm.u_comments; //replace with your field name

current.comments = comments;

}(current, previous);

 

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh

Hi, 

        I am not sure if this is the answer if this the right approach. The comments field is in sysapproval_approver table (image). The custom field (string) is in ritm table. What I want is to move the value from this field (sc_req_item) to the approvers (sysapproval_approver), specifically to the "Comments" field. I hope this could bring more light to this issue. Here is my code (that is not working) from the after Update BR in sc_req_item. I am using a specific record to make the change but my goal is every record that make changes to the custom field.

 

var gr_approvalinfo = new GlideRecord("sysapproval_approver");       gr_approvalinfo.addEncodedQuery("state=requested^document_id=c9d9b5091beff1582ed5da46b04bcb3b");
        gr_approvalinfo.query();
        //var approvalSys_id = '';

        while (gr_approvalinfo.next()) {
            gr_approvalinfo.comments = current.u_customfield; //custom field name
            gr_approvalinfo.update();
 

 

@LuLe Game Understood now!

 

Update your code with the following one, let me know if it is not working.

 

var gr_approvalinfo = new GlideRecord("sysapproval_approver"); gr_approvalinfo.addEncodedQuery("state=requested^sysapproval=" + current.getUniqueValue() + "^ORdocument_id=" + current.getUniqueValue());

gr_approvalinfo.query();

while (gr_approvalinfo.next()) {

   gr_approvalinfo.comments = current.getValue('u_customfield'); //custom field name

   gr_approvalinfo.update();

}

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh

@LuLe Game I have tested the above code in My PDI, it's perfectly working fine.

 

See the screenshots below for, Business Rule configuration and Test results.

 

AnveshKumarM_0-1704421267784.png

 

AnveshKumarM_1-1704421295617.png

 

AnveshKumarM_2-1704421311187.png

AnveshKumarM_3-1704421335849.png

 

 

 

Thanks,
Anvesh