- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 05:33 PM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 10:54 PM
@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)
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 07:50 PM
Hi @chercm
There is an OOTB field called requested_for in RITM form and you have another field created u_requested_for field.
You have populated Requested for variable in to the u_requested_for field. And you have another variable called name_of_user and you want it in OOTB requested_for field?
If yes, if the name_of_user variable is of type reference you can use the same Business Rule way to copy the variable to field, but if the variable is of free form text type , you can not. Why because the requested_for field is of type Reference refering to User table which accepts sys_id of a user record.
Let me know if you have any queries.
Please mark my answer helpful and accept as solution if it helped 👍✅
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 07:58 PM
@AnveshKumar M the situation is the requestor or might not the same user. I have allowed the user to pick from the sys_user as the name_of_user. How do I set the business rule as before and where to enter the script ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 08:01 PM
@chercm then it should be same way as you did earlier. Add the below code to your existing before insert business rule.
current.requested_for = current.variables.name_of_user;
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 08:03 PM
@AnveshKumar M i did not managed to do it and was having difficulty