- 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:40 PM
Hi Desertmoxie,
Seems like the question is already resolved but just as a note, gs.getUserName() does not take any argument.
FYR,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2022 02:41 PM
As others have pointed out there are some easier ways to get the user name. Keep in mind that there are now two different "Requested for" fields. One is on the Request that the Requested Item is attached to and this is the oldest one and the one the system is useally setup to use. Several versions ago when they introduced the "Requested for" variable type they added another "Requested for" field to the Requested item table. These two different fields are set based on if you have a "Requested for" variable on your catalog item.
https://docs.servicenow.com/bundle/rome-servicenow-platform/page/product/service-catalog-management/reference/r_VariableTypes.html#d280642e1223
So depending on how your catalog item is setup you can use either of the two below to get the user_name field or the display value for the user
user_name field
var username = current.requested_for.user_name.toString();
var username = current.request.requested_for.user_name.toString();
For display value
var username = current.requested_for.getDisplayValue();
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:51 PM
Thanks for all the help!!!
