- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 12:59 PM
I am new to ServiceNow. We have added a new field to our sc_task table called u_requested_for_userid. This field is to capture the user's id value. In other words, the value you see in the UserID field on the sys_user table but the field name is 'user_name'. For the most part it is the lastname+firstinitial (one's log id). I have tried the following code within a new business rule and cannot get the field populated. I even tried dot walking the value and returns a blank. Any assistance would be greatly appreciated.
For example,
Requested_for = John Smith
The value I need from the user table is SmithJ
(function executeRule(current, previous /*null when async*/) {
populateRequestForIDField();
function populateRequestForIDField() {
//If we have a request item, get the original request
if(!current.request_item.nil()) {
var request_item = new GlideRecord('sc_req_item');
if(request_item.get('sys_id', current.request_item)) {
current.u_requested_for_userid = request_item.request.requested_for.user_name;
}
}
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 12:31 PM
Hi there,
I tested with a before insert Business Rule on sc_task with below code, works.
Though, your field is called User ID. So I guess you would like to have the User ID and not the Display Name of the User? Looking at your table image, you made User ID a reference, to sys_user. So this won't work 😞 You have to make this a String field (then Brian's script will work).
Have you also considered just adding the dotwalked field from request to the form lay-out? Or is there a specific reason to have the requested for actually added to the sc_task table?
(function executeRule(current, previous /*null when async*/) {
current.u_requested_for_userid = current.request.requested_for;
})(current, previous);
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
---
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 01:15 PM
Just to clarify the u_requested_for_userid is a filed on the sc_task table and not a catalog item variable correct?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 01:28 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2019 01:32 PM
Then you business rule should be as simple as below. This is a before insert running on the sc_task table. If you do it as an after insert you will need to add current.update();
(function executeRule(current, previous /*null when async*/) {
// Add your code here
current.u_requested_for_userid = current.request.requested_for.user_name;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2019 12:22 PM
Thank you for the response. I applied the code and it is still returning a blank value?? Any other ideas or suggestions?