- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 01:57 PM
We built a business rule to post RITM variable info as an sc_task worknote so technicians have the information at their fingertips without going back to RITM. However, I'm trying to get the Requested For from the Request/RITM to display, but it's not working.
Everything in the below code works except for the bolded //get Username from Requested for. Would appreciate input, thanks!
(function executeRule(current, previous /*null when async*/) {
// get Username from Requested For
var username = gs.getUserName(current.requested_for);
//Get Variables and loop through
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.getValue('request_item'));
var workNote = "";
set.load();
var vs = set.getFlatQuestions();
gs.log('Size: ' + vs.size());
for (var i = 0; i < vs.size(); i++) {
if (vs.get(i).getDisplayValue() != '') { // Only get variables that were filled out
workNote = workNote + vs.get(i).getLabel() + ": " + vs.get(i).getDisplayValue() + "\n";
}
}
current.work_notes = "Requested for user name: " + username + "\n" + workNote + "\n";
current.update();
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 02:36 PM
Thanks, we had to use the following with dot-walk for request.requested_for in order to work.
var username = current.request.requested_for.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 02:17 PM
Hi,
Why don't you simply dot walk to get the requested for's user name?
var username = current.requested_for.user_name;
Is there anything I am missing?
Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 02:17 PM
if you want the user's display name for requested_for field, you can't get it using gs like that.
try using
var username = current.requested_for.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 02:36 PM
Thanks, we had to use the following with dot-walk for request.requested_for in order to work.
var username = current.request.requested_for.getDisplayValue();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 02:38 PM
yep that makes sense if you wanted to get the user's display name from the parent request, and not from the individual request item.