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.

Service Catalog Task Client Script accessing item

abrahams
Kilo Sage

I am trying to access the name of the Service Catalog Item in a sc_task client script. I seem to be able to get the sys_id of the item with the following ... var item = g_form.getReference('request_item').cat_item; ... if possible I would like to get the name.

I tried var item = g_form.getReference('request_item').cat_item.name; but that just gives me undefined. I also tried var item = g_form.getReference('request_item').name; ... that also gives me undefined. I can get the short description by using var item = g_form.getReference('request_item').short_description; ... Would anyone know how to get the name of the item?

2 REPLIES 2

Mark Stanger
Giga Sage

'getReference' will only let you dot-walk one level deep - which in this case will let you get the sys_id of the catalog item associated to your request item record. If you want to get information about the catalog item (the name for example) you have to perform a second query against the catalog item table using the sys_id of the item.

You'll want to be careful doing this though as it will cause a momentary lockup of the browser which may be perceived as a performance problem when it's really bad design. I would recommend using GlideAJAX to perform the whole query on the back-end with an async query. You can find more information about GlideAJAX on the wiki.


abrahams
Kilo Sage

Thank you!