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 Aman,

As shown in the image below, I am unable to perform a dot walk using the data picker in this situation and must just add the user's name since user name is a reference to the User table.

find_real_file.png

 

Thanks,

JRY

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