Catalog client script returns sysID instead of user's name

johnsonjohn
Tera Contributor

Hi - I know there are several posts about this and I've read through most of them, but I don't know how to apply it to my use case.  I have a request form with 2 reference fields, requested_by and requested_for.  I created an onChange catalog client script that intends to show a message with the user's name in this field (i.e. if requested_for has a value, show that name, if it's blank show name in requested_by).  The value is stored in a variable called vdiuser.  However, using this script, vdiuser shows the sysID not the actual user's name.  I think I'm supposed to use a script include, but I'm not sure what that means and what the script should say.  Thanks in advance for your patience and guidance for this Service Now newbie.

 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}

//Type appropriate comment here, and begin script below
var deletetype = g_form.getValue('u_vdi_delete_type');
var reqFor = g_form.getValue('requested_for');
var reqBy = g_form.getValue('requested_by');
var vdiuser;

if(reqFor) {
vdiuser = reqFor;
}
else {
vdiuser = reqBy;
}

if (deletetype == 1) {
g_form.showFieldMsg('u_vdi_delete_type', '!!!! Warning: Choosing this option will delete ALL VDIs for ' + vdiuser + '. This action is irreversible !!!', 'error');
g_form.hideFieldMsg('u_vdi_delete_vdiname');
}

else {
g_form.showFieldMsg('u_vdi_delete_vdiname', 'Please note that the VDI name must be entered exactly correct for the deletion to occur', 'info');
g_form.hideFieldMsg('u_vdi_delete_type');
}


}

1 ACCEPTED SOLUTION

Sorry I assumed this was for Service Portal.

 

Try this instead will work for both.

 

 var reqFor = '';
 var reqBy = ''; 

if(window === null){
//run sp code
  reqFor = g_form.getDisplayValue('requested_for');
  reqBy = g_form.getDisplayValue('requested_by');
}else{
//run desktop code
  reqFor = g_form.getDisplayBox('requested_for').value;
  reqBy = g_form.getDisplayBox('requested_by').value;
}

View solution in original post

21 REPLIES 21

Bhojraj Dhakate
Tera Expert

Hi John,

find below correction in script: 

instead of "vdiuser = reqFor;" use "g_form.setValue('vdiuser',reqFor );"

ar deletetype = g_form.getValue('u_vdi_delete_type');
var reqFor = g_form.getValue('requested_for');
var reqBy = g_form.getValue('requested_by');
var vdiuser;

if(reqFor) {
vdiuser = reqFor;  //g_form.setValue('vdiuser',reqFor ); Use This
}
else {
vdiuser = reqBy; //g_form.setValue('vdiuser',reqBy ); Use This
}

let me know if it works.

Thanks,

Bhojraj

Hi Bhojraj, thanks for your response.  Unfortunately, that doesn't seem to work.  Here's the modified part of that script:

 

var deletetype = g_form.getValue('u_vdi_delete_type');
var reqFor = g_form.getValue('requested_for');
var reqBy = g_form.getValue('requested_by');
var vdiuser;

if(reqFor) {
//vdiuser = reqFor;
g_form.setValue('vdiuser',reqFor);
}
else {
//vdiuser = reqBy;
g_form.setValue('vdiuser',reqBy);
}

 

When I check the catalog item, it now says "undefined" instead of the sysID as it was previously saying.

Hi,

can you tell me the onchange variable name that you used in onchange client script?

Thanks,

Bhojraj

Hi - the onChange variable is u_vdi_delete_type