Using gs.getUserName to get the Requested For

desertmoxie1
Tera Expert

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);

1 ACCEPTED SOLUTION

desertmoxie1
Tera Expert

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();

View solution in original post

7 REPLIES 7

Sunjyot Singh
Kilo Guru

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.

Jon Barnes
Kilo Sage

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();

desertmoxie1
Tera Expert

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();

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.