Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

"Requested For" in RITM not working correctly

anirban300
Kilo Guru

We have created the variable "On Behalf of" with Type "Reference" in a catalog item. We want to link the data on this field with the field "Requested For" in RITM. So, I have written a "before insert/update"  business rule on the table "sc_request" to link both the field as below

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

    var grRITM = new GlideRecord('sc_req_item');

    grRITM.addQuery('request', current.sys_id);

    grRITM.query();

    while (grRITM.next()) {

        if (!JSUtil.nil(grRITM.variables.requested_for)) {

            current.requested_for = grRITM.variables.requested_for;
       grRITM.update();

        }

    }

})(current, previous);

The flow designer is taking requested for's approval and sending approval. But, still it is sending approval to opened by's approver

1 ACCEPTED SOLUTION

Hi,

Glad to know that my script worked.

If my response helped please mark it correct and helpful to close the thread.

check the requested for field on RITM is field from RITM or dot walked from REQ field?

Also in the XML requested_for field is of RITM so definitely the form field is a dot walked from REQ

so if you wish you can update that as well

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

    var grRITM = new GlideRecord('sc_req_item');
    grRITM.addQuery('sys_id', current.sys_id);
    grRITM.query();
    if (grRITM.next()) {
        if (!JSUtil.nil(grRITM.variables.requested_for)) {
            grRITM.requested_for = grRITM.variables.requested_for;
            grRITM.update();
            
            var req = current.request.getRefRecord();
            req.requested_for = grRITM.variables.requested_for;
            req.update();
            
        }
    }

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Hi Ankur,

Thank you soo much for the suggestion. Your code corks successfully and the approver went to requested for's manager. But as you can see below in the RITM, it is still showing opened by's name in the requested for but in the XML its the correct person's name which I have set.

find_real_file.png

Hi,

Glad to know that my script worked.

If my response helped please mark it correct and helpful to close the thread.

check the requested for field on RITM is field from RITM or dot walked from REQ field?

Also in the XML requested_for field is of RITM so definitely the form field is a dot walked from REQ

so if you wish you can update that as well

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

    var grRITM = new GlideRecord('sc_req_item');
    grRITM.addQuery('sys_id', current.sys_id);
    grRITM.query();
    if (grRITM.next()) {
        if (!JSUtil.nil(grRITM.variables.requested_for)) {
            grRITM.requested_for = grRITM.variables.requested_for;
            grRITM.update();
            
            var req = current.request.getRefRecord();
            req.requested_for = grRITM.variables.requested_for;
            req.update();
            
        }
    }

})(current, previous);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Ankur,

Thank you again. It worked well. it, I am getting this error while submitting the catalog item.

find_real_file.png

Hello Ankur,

Can you also check my below query similar to this?

Variable User data in RITM Fequested For - Developer Community - Question - ServiceNow Community

Regards

Anirban

Harish KM
Kilo Patron
Kilo Patron

Hi you can handle this in flow designer itself no need BR.

just use GetVariableAction --> add the variables from left to right side (slush bucket)

use update record action and set value directly to requestedfor field by using dot walk to variables

Refer attached screenshot

Regards
Harish