i have a different user name in the ritm request for requested for field

chercm
Mega Sage

i followed the article : https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0852249

 

1. Add a new custom 'Requested For' [u_requested_for] field to the 'sc_req_item' table.
2. Add a variable['requested_for'] at the item level to capture the user for whom this item is requested.
3. Create a Before insert business rule on 'sc_req_item' table to copy the value of variable ['requested_for'] to the sc_req_item.u_requested_for field using code that looks like below:
current.u_requested_for = current.variables.requested_for; // Copy the variable value to the RITM's Requested For field

 

from my flow designer , i have a variable name_of_user in the stashbucket, how can i use it to update the requested for field on the Request item form?

 

chercm_0-1696725225465.png

 

1 ACCEPTED SOLUTION

@chercm try changing the before insert business rule to after Insert business rule and change the code to below one.

 

Create a new before insert Business rule on table sc_req_item and add the following script.

 

 

 

(function executeRule(current, previous){

 

var gr = new GlideRecord('sc_request');

 

if(gr.get(current.request)){

 

gr.requested_for = current.variables.name_of_user;

 

gr.update();

}

 

})(current, previous)

Thanks,
Anvesh

View solution in original post

15 REPLIES 15

@chercm post the screenshot of variable configuration and business rule and the ritm form.

Thanks,
Anvesh

@AnveshKumar M here is the variable setup 

 

chercm_0-1696737736845.png

business rule 

 

chercm_1-1696738125776.png

 

chercm_2-1696738147749.png

chercm_3-1696738187017.png

 

 

@chercm do the following changes.

1. Variable Setup: Change the value field to sys_id, and label(s) field to name.

 

IMG_20231008_095927.png

 

2. Create a new before insert Business rule on table sc_req_item and add the following script.

 

(function executeRule(current, previous){

var gr = new GlideRecord('sc_request');

gr.get(current.request);

gr.requested_for = current.variables.name_of_user;

gr.update();

})(current, previous)

 

 

Try these and let me know.

 

Please mark my answer helpful and accept as solution 👍

Thanks,
Anvesh

@AnveshKumar M  

 

it is still showing as current user. not working 

 

getting this error. :

ErrorUnique Key violation detected by database ((conn=49635) Duplicate entry 'f1b7f6382f353110207170682799b6d9' for key 'PRIMARY')

 

chercm_0-1696743033422.png

 

@chercm try changing the before insert business rule to after Insert business rule and change the code to below one.

 

Create a new before insert Business rule on table sc_req_item and add the following script.

 

 

 

(function executeRule(current, previous){

 

var gr = new GlideRecord('sc_request');

 

if(gr.get(current.request)){

 

gr.requested_for = current.variables.name_of_user;

 

gr.update();

}

 

})(current, previous)

Thanks,
Anvesh