Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to get Value instead of Sys.id in a Catalog Client Script?

cms1
Tera Contributor

I am fairly new to scripting. I've used this script before and it has worked. Now, I'm trying it on a different Variable and it's not working.

My goal is to reference the variable "u_workstation" and provide the product name (model_id) of the workstation to the variable "u_model_make_laptop".

Everything seems to be working except the value that appears in "u_model_make_laptop" is a sys_id   value not the display value.


Please help

function onChange(control, oldValue, newValue, isLoading) {

    var modelId = g_form.getReference('u_workstation');

      if (modelId.model_id)

  g_form.setValue('u_model_make_laptop', modelId.model_id);

  }

    find_real_file.png

2 REPLIES 2

Chuck Tomasi
Tera Patron

Hi Candice,



What is the field type of model_id on the table where the u_workstation record is pointing? I suspect it is another reference field.



Although it's a few lines more, you may want to consider using a GlideAjax construct in your client script to get back the exact data you want.



Helpful video in episode 33: TechNow Episode List


Docs: Client Scripts


Docs: GlideForm


Docs: GlideAjax


Client Script Best Practices - ServiceNow Wiki      


You are correct. model_id is another reference type field. I will review the videos you posted and hopefully be able to create the GlideAjax.


Thank you.