The CreatorCon Call for Content is officially open! Get started here.

I am getting the Sys Id of a reference field on Service Catalog while using a catalog client script.

Rhonda9
Tera Expert

Hello,

 

I am having an issue with a catalog client script.   I am trying to pull in the department name of requested for variable and it is showing the sys id of the variable instead of the department name.   I'm not sure what I am doing wrong....  I changed setValue to getDisplayValue  and still not getting the results I need.  

 
 This is my client script
function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
var requestedFor = g_form.getReference('requested_for', setDepartment);
 
 function setDepartment(requestedFor) {
     if (requestedFor) g_form.setValue('account_docusign_requesting_department_name', requestedFor.department);
 
 
}
}

 

 

Rhonda9_1-1699563753175.png

 

 

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

Hi Rhonda,

With getReference, you only have access to the field values on the referenced table (sys_user in this case) not fields on another referenced table (cmn_department.name). So you can't dot-walk to get to it or anything else.  It looks like you could change the 'Requesting Department Name' variable to a reference on cmn_department, then all would be fine as it would show the name whilst storing the sys_id.  If that's not what you're looking for then you'll have to change your approach to a GlideAjax calling a Script Include.  Here's a guide on how to make that work, so you can return the department Name instead of the sys_id.

https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet-updated/ta-p/2... 

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Hi Rhonda,

With getReference, you only have access to the field values on the referenced table (sys_user in this case) not fields on another referenced table (cmn_department.name). So you can't dot-walk to get to it or anything else.  It looks like you could change the 'Requesting Department Name' variable to a reference on cmn_department, then all would be fine as it would show the name whilst storing the sys_id.  If that's not what you're looking for then you'll have to change your approach to a GlideAjax calling a Script Include.  Here's a guide on how to make that work, so you can return the department Name instead of the sys_id.

https://www.servicenow.com/community/developer-articles/glideajax-example-cheat-sheet-updated/ta-p/2... 

Rhonda9
Tera Expert

It is working now.  Thank you so much!

You are welcome!

Tony Chatfield1
Kilo Patron

Hi, getReference() returns the 'requested_for' record/object, and the department field of any reference field within a record is the referenced record sys_id, so I think this is correct\expected behavior.


If you require the 'name' of the department client side, I think that you would need to return the department record;
However, I believe that getReference() is not recommended best practice and for this type of requirement I would use GlideAjax and a server side script-include to return the department name.