logo

NJP

Auto-populate a variable based on a reference type variable (Utah)

Import · Feb 13, 2023 · article

Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

Hi there,

Last week I made a LinkedIn post about the new Utah release feature "Auto-populate a variable". A minor post, though wow so many interest in it! Personally for me this is also the "wow" feature of the Utah release. Such a minor new feature, though potentially a big impact for everyone working on Service Catalog. A lot of use cases for populating Variables through Catalog Client Script (or Catalog UI Policy using the Script fields) can be reverted into using the "Auto-populate" option.

Auto-populate

Let's immediately jump into the Auto-populate functionality. This is what the Auto-populate looks like on a Variable:

01.png

That's it. A new section, you select the Dependent question which will be a Variable of type reference within your Catalog Item, select the Reference, and choose the Dot walk path. You can actually dotwalk, so you are not limited to only the fields on the Reference table.

02.png

Actually there's not much more to write on this, the Auto-populate functionality is just so straightforward! Have a Variable of type reference on your Catalog Item, create a new Variable that you want to Auto-populate and fill in the three fields under the new Auto-populate section, and that’s it.

While testing this, the responsiveness looks really good (perhaps even better than GlideAjax with getXMLAnswer), it works also onLoad, and when clearing the dependent Variable the Auto-populated Variable will also be cleared.

03.png

Note: You might have noticed that the release notes on the ServiceNow Docs mentions this new functionality using Catalog Builder. Though like shown above, Catalog Builder is not mandatory to achieve the Auto-populate functionality.

Pre-Utah

With the Quebec release ServiceNow did introduce "Catalog Data Lookup Definitions". A nice improvement, though just a bit too many steps to get it working. Also Catalog Data Lookup Definitions don't work onLoad.

Other methods to Auto-populate a Variable would be methods like using GlideAjax (ideally with getXMLAnswer), getReference, etcetera. While using GlideAjax works well, it can be a bit complex and is a time-consuming task to develop. Because of this a lot of developers use the lesser method of getReference.

Read more about this subject in one of my earlier articles: Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!

---

And that's it . Hope you like it. If any questions or remarks, let me know!

Kind regards,

Mark Roethof

Independent ServiceNow Consultant

4x ServiceNow Developer MVP

4x ServiceNow Community MVP

---

View original source

https://www.servicenow.com/community/developer-articles/auto-populate-a-variable-based-on-a-reference-type-variable-utah/ta-p/2475511