We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

How to copy incident Affected user to Catlog item Requested for?

jugantanaya
Tera Contributor

Hi,

I need to Create a Request from an Incident by using context menu(UI Action), but when I select any catalog Item Requested for is not getting auto populated(same as incident Affected User). I have written one BR but it seems not working.

jugantanaya_1-1777021700356.png

 

 

jugantanaya_0-1777021646116.png

 

BR: Copy Affected User to Requested For

Table: sc_request

When: Before

              Insert

              Update

Condition: Parent is not Empty

Script:

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


// Check if RITM was created from an Incident
    if (current.parent && current.parent.sys_class_name == 'incident') {

        var inc = new GlideRecord('incident');
        if (inc.get(current.parent)) {

            // Copy Affected User to Requested for
            current.requested_for = inc.affected_user;

            // Optional: also copy to opened_for or variables if needed
            // current.opened_for = inc.affected_user;
            current.variables.affected_user = inc.affected_user;
        }
    }

})(current, previous);
 
Please help.
Thanks in advance.
 
Regards,
Juganta

 

 

 

2 REPLIES 2

Ankur Bawiskar
Tera Patron

@jugantanaya 

so what are your findings with the BR?

is the field name correct? affected_user

I couldn't see that as OOTB field

if it's custom field then it must be starting with u_

55.png

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

pr8172510
Kilo Sage

Hi @jugantanaya,

1. Wrong table – You're using sc_request, but the "Requested for" field actually lives on the RITM (sc_req_item). The request header doesn't have that field.

2. Parent field is tricky – When you use the "Create Request" UI action, current.parent isn't always populated yet. So your condition might be failing right there.

3. Variables won't work here – current.variables doesn't work in a Business Rule on sc_request. That's just not how it's designed.

4. Field name check – As others mentioned, affected_user isn't an OOTB field on incident. If you created it custom, it should be u_affected_user.

 

Option 1: Fix it in the UI Action 

Instead of a Business Rule, just set the value when you create the cart:

var cart = new Cart();
var item = cart.addItem('your_catalog_item_sys_id');

// Grab the affected user from the incident
cart.setRequestedFor(current.u_affected_user || current.caller_id);

var rc = cart.placeOrder();
action.setRedirectURL(rc);

This works every time because you're setting it before the RITM is even created.


Option 2: Move your Business Rule to the right table

If you really want a Business Rule, put it on sc_req_item instead:

(function executeRule(current, previous) {

    if (current.request && current.request.parent) {

        var inc = new GlideRecord('incident');
        if (inc.get(current.request.parent)) {

            current.requested_for = inc.u_affected_user; // or inc.caller_id
        }
    }

})(current, previous);