The Now Platform® Washington DC release is live. Watch now!
on ‎02-10-2021 09:40 PM
Hi there,
Working often with Service Catalog? You probably come across wanting to populate Variables onChange depending on a different Variable. Up to the Paris release, the best answer would be to use a Catalog Client Script which uses GlideAjax (with getXMLAnswer). Other possibilities like getReference would be possible, though are the kiddy solutions.
Though why do we always need to script this?! Well with the Quebec release… Eureka! The Release Notes mentions "Eliminate scripting by leveraging data lookup rules that can now be set on any table within the current scope."
(Small note to this, this does concern data lookups on the same table)
Let's get after it!
Catalog data lookup definition
Say what? Catalog data lookup definition? You might have heard of Data lookup definitions within the Platform, though actually, these are also available for the Service Portal. Catalog data lookup definition has been added with the Paris release, one thing though… somehow ServiceNow forgot to add the Related Lists concerned to the Catalog Item form (not only for upgraded instances, also out-of-the-box). With the Quebec release this has been solved, the Related List has been added.
Want to know more about Catalog data lookup definitions, see this article from
Service Catalog Data Lookup
Catalog data lookup rules on any table
The Catalog data lookup definition added with the Paris release is already a nice game changer within Service Catalog. Though now having data lookup rules available on any table, WOW! Gone is the need to always script data lookups through Catalog Client Scripting with (ideally) GlideAjax (and getXMLAnswer).
(If you still need to use Catalog Client Scripting with GlideAjax and getXMLAnswer, read about it in one of my previous articles: Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!
So what is it actually about then, what is the WOW?
Catalog Data Lookup Definition
Let's start by adding a user reference variable and a location reference variable. Next up, adding a Catalog Data Lookup Definition.
Okay, so now you can select any table here. What does that offer us? After adding the Catalog Data Lookup Definitions record, two Related Lists get visible: Catalog Matcher Variable Definitions and Catalog Setter Variable Definitions. The titles already spoil what there about, though let's walkthrough.
Catalog Matcher Variable Definition
Catalog Setter Variable Definition
Result
After adding the Catalog Data Lookup Definition and the Catalog Matcher and Setter Variable Definitions, when changing the matcher Variable on your Catalog Item, the setter Variable on your Catalog Item will be automatically populated! No scripting involved, just basic configuration, WOW!
Small side note which I mentioned earlier. This does concern data lookups on the same table. So for more complex data lookups, retrieving data from other tables, having additional GlideRecord queries, etcetera: you would still need to use Catalog Client Script and GlideAjax (with getXMLAnswer).
---
And that's it actually. Hope you like it. If any questions or remarks, let me know!
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful. Interested in more articles, blogs, videos, and Share Projects on Service Catalog I published? - Service Catalog |
Kind regards,
Mark
2020-2021 ServiceNow Community MVP
2020-2021 ServiceNow Developer MVP
---
Fantastic article! I got this working after installing the following missing plugin in my upgraded Quebec instance:
"Data Lookup and Record Matching Support for Service Catalog", which was dependent on a pre-existing plugin that I had already enabled in my environment, "Data Lookup and Record Matching Support".
Hi
I had tried this but it is displaying sys id
Hi
You are setting the value in Multi line text instead of Reference
Hope it helps..
-Murthy
Same for me on trying to set manager name of requestor.
Please help me.
No problem helping you, though you do have to provide some info. No info, no help.
Kind regards,
Mark
I did mistake of setting field type of "Manager" as "Single Line Text" on changing it to 'Reference' and table to "sys_user" issue got resolved. Solution which u have provided worked. Thanks !!
And my client script also started working which I worked out before knowing about the "Catalog Data lookup definition" feature.
Solution:
Hi
Is it possible to have a catalog data lookup definition work on load as well?
We often use the "requested_for" type field in catalog item which automatically fills in the current user. Based on the requested_for field we want to use the catalog data lookup definitions to populate other variables in the catalog item but they are not populated due to the fact that the requested for was already filled in. For now the work-around is the manually change the user in the requested for field
Kind regards, Martin
Not onLoad. In such a scenario generally you can use the default value field on variables instead.
A workaround to use Catalog Data Lookup onLoad could be to fill the requested for with an onLoad client Script instead of default value. This will trigger the Catalog Data Lookup to work.
Kind regards,
Mark
I tried your approach using a custom table but it didn't appear to populate anything.
The table is referenced in both of my fields:
I am trying to use this for a variable set.
User is selected.
Email & Location fields are populated with data from user record.
No issue with email.
But when I try a second item, first item is skipped and second only returns sys_id.
Can I reference a table more than once?
I was trying to create seperate defitions on same table.
I added location to same defintion, Name returned for 1st (good), but system id returned for location.
Hi Lon,
Got stuck on this for a bit myself, The variable field to populate should match the type of data being received. If receiving a sys id it should be a reference field pointing to the related table.
So the the variable type for the field location should be a reference pointing towards the cmn_location table. it should then show the location name value.
for anything that is a string that is being populated you can just use a text box.
Hope that helps,
Kind Regards,
Andy
can you explain me how you got for hardware and ram field also.in my catalog i have manager is single line text in that how to configure data lookup definition.
can someone help me on this catalog is same as above
I have tried this for Based on Asset selection Product Model and account should display but it is not working and not populating any values. Can anyone help on this?
Hi, thank you for this article but...
Any idea why the Data lookup definition based on sys_user table does not populate fields IF USER IS INACTIVE?
If user is active, it works perfectly!
Can Catalog lookup definitions be used with submitted by (current user)?
Thanks for the article, I got Requested for fields to populate as expected. I am trying to get this working with Submitted by. But when I apply the same steps, only the Name is returned as opposed to manager, email, or title.
Hello everyone, I tried auto populating a field based on the selected CI. Both fields are reference fields, the values are both on the cmdb_ci table.
Now the field in which the user should select the CI shows the value that should be auto populated instead of the name of the CI.
Field "Betroffenes Endgerät" should show the name of the selected CI, field "Handelsraum" should show the value (either true or false) for the selected CI. The auto population works.
To anyone else trying this out and having problems: I've found I usually need to clear the cache on the instance (cache.do) before this will start working. Otherwise, you might have to wait a few hours for it to kick in. This is assuming the setup is correct of course.
Dear All,
Greetings !!
I tried to implement the 'Catalog Data Lookup Definitions' and it works fine when there is a non-null value in the matcher table field in the Setter definition, however, system does not replace it with blank on the catalog item form if the matcher table field in the Catalog Setter Variable Definition is null/blank on the User table.
For instance, I have a field named 'Requested For' on the catalog item form and I have marked it as a Matcher Table field on Catalog Matcher Variable Definition and I have a field named Location that I would like to auto-populate based on the 'Requested For' selected.
Now, this solution works absolutely fine when there is a non-null Location value in the Location field in the User table, however, if I select a user in the 'Requested For' field for whom Location is null/blank in the User table, system does not update the value in the Location field on the catalog Item form to null/blank. It does not remove the non-null value in the Location field which was populated for the previous user(for whom the Location field in sys_user table is non-null).
Has anyone else experienced this issue? If yes, could you please suggest a resolution for this problem?
Thanks.
Mark, thank you for providing these instructions. Frustratingly, I ran head long into a scope issue trying this on a Record Producer (scope = Customer Service) for Case and I could not initiate a Catalog Data Lookup Definition on the account (Global scope) table.
However, I was able to accomplish my task using Auto-populate on the variable, which did allow me to dot-walk to the Account record even though the RP was in the "wrong" scope.
Like mentioned in two posts back, this "Catalog Data Lookup Definitions" wow feature is missing an important part! When it does not find a match, the target field will not be cleared on the Catalog Item or Order Guide form, resulting in any previous matching value is kept.
To work around this I created a Catalog Client Script which always clears the target field on the change (onChange) of the source/match field. This works because, it seems that, the execution order is 1) Catalog Client Script and then 2) Catalog Data Lookup Definitions.
This is an ugly workaround for functionality which is missing in the "Catalog Data Lookup Definition" feature.