Error: Cannot find function getDisplayValue in object

JRY
Mega Guru

Hello,

I'm trying to update the RITM description using the flow designer, but I'm getting the user's SYS ID rather than their name. This user name is a reference variable in a variable set, therefore I attempted using script rather than a data picker, but I was unable to use getDisplayValue since an error was displayed. Could someone please tell me what went wrong with the script below the bold line?

find_real_file.png

var response = '';
var ritmSysId = fd_data.trigger.request_item.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);

response += 'Requested By : ' + rec.variables.requested_by.getDisplayValue()+'\n';
response += 'Phone : ' + rec.variables.requested_for_phone +'\n';
response += 'Requested For : ' + rec.variables.requested_for.getDisplayValue()+'\n';
response += 'Which System : ' + rec.variables.which_system +'\n';
response += 'Organization : ' + rec.variables.organization +'\n';
response += 'Apply Access to : ' + rec.variables.apply_access_to +'\n';
response += 'ID Type : ' + rec.variables.id_type +'\n';
response += 'Model SAP access after existing user : ' + rec.variables.model_sap_access_after_existing_user +'\n';
response += 'Add/remove other roles : ' + rec.variables.add_remove_other_roles+'\n';
response += 'Type of system id : ' + rec.variables.type_of_system_id+'\n';
response += 'User group action : ' + rec.variables.user_group_action+'\n';
response += 'System Selection : ' + rec.variables.system_selection+'\n';
response += 'Group Name : ' + rec.variables.group_name +'\n';
response += 'New group Name : ' + rec.variables.new_group_name +'\n';
response += 'Group Description : ' + rec.variables.group_description +'\n';
response += 'User group Owner : ' + rec.variables.user_group_owner +'\n';
response += 'Primary Approver : ' + rec.variables.primary_approver +'\n';
var mrvs1 = JSON.parse(rec.variables.summary_of_additional_users);
mrvs1.forEach(function(item) {
response += 'User Name : ' + item.user_name +'\n';
response += 'SAP ID : ' + item.additional_user_sap_id +'\n';
});
response += ' Business Justiification : ' + rec.variables.business_justification+'\n';
response += 'Additional Comment : ' + rec.variables.additional_comments+'\n';

return response;
 
Thanks,
JRY
1 ACCEPTED SOLUTION

Chaitanya Redd1
Tera Guru

Hi,

Can you try below script it might work. 

var response = '';
var ritmSysId = fd_data.trigger.request_item.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);

var getUserName = function (user_sys_id) {
var grUser = new GlideRecord('sys_user');
grUser.get(user_sys_id);
return grUser.name;
}
response += 'Requested By : ' + rec.variables.requested_by.getDisplayValue()+'\n';
response += 'Phone : ' + rec.variables.requested_for_phone +'\n';
response += 'Requested For : ' + rec.variables.requested_for.getDisplayValue()+'\n';
response += 'Which System : ' + rec.variables.which_system +'\n';
response += 'Organization : ' + rec.variables.organization +'\n';
response += 'Apply Access to : ' + rec.variables.apply_access_to +'\n';
response += 'ID Type : ' + rec.variables.id_type +'\n';
response += 'Model SAP access after existing user : ' + rec.variables.model_sap_access_after_existing_user +'\n';
response += 'Add/remove other roles : ' + rec.variables.add_remove_other_roles+'\n';
response += 'Type of system id : ' + rec.variables.type_of_system_id+'\n';
response += 'User group action : ' + rec.variables.user_group_action+'\n';
response += 'System Selection : ' + rec.variables.system_selection+'\n';
response += 'Group Name : ' + rec.variables.group_name +'\n';
response += 'New group Name : ' + rec.variables.new_group_name +'\n';
response += 'Group Description : ' + rec.variables.group_description +'\n';
response += 'User group Owner : ' + rec.variables.user_group_owner +'\n';
response += 'Primary Approver : ' + rec.variables.primary_approver +'\n';
var mrvs1 = JSON.parse(rec.variables.summary_of_additional_users);
mrvs1.forEach(function(item) {
response += 'User Name : ' + getUserName(item.user_name) +'\n';
response += 'SAP ID : ' + item.additional_user_sap_id +'\n';
});
response += ' Business Justiification : ' + rec.variables.business_justification+'\n';
response += 'Additional Comment : ' + rec.variables.additional_comments+'\n';

return response;
 
If my answers help anyway. Please mark it helpful.
 
Regards,
Chaitanya

View solution in original post

11 REPLIES 11

Hi Abhijit,

summary_of_additional_users is a Variable set as you can see below.

find_real_file.png

Your script looks good, what values you are getting in response variable with that script, you must be getting sys_id of the user, isn't it?

By marking my response as correct or helpful, you contribute to helping future readers with similar issues.
Regards,
Abhijit
ServiceNow MVP

Aman Kumar S
Kilo Patron

Can you share more details about "summary_of_additional_users" what kind of field it is?

Is it a list collector? then dot walk will not work, you will have to glide each record to find relevant values.

Best Regards
Aman Kumar

Hi Aman,

summary_of_additional_users is a Variable set as you can see below.

find_real_file.png

What I could deduce here, when you are parsing the MRVS data, it stores the data as object but the behavior would be same as list collector, as in how you can't dot-walk from each individual list elements to get the dot walked fields, that would be the same case here.

If at you want to fetch other details from usser_name reference field, you will have to glide the table then pass user_name data to get display value or other relevant fields. 

getDisplayValue or other functions won't work in this case.

Best Regards
Aman Kumar