logo

NJP

New in Utah! Auto-populate variable based on a reference

ServiceNow Archives » Rubén Ferrero · Feb 05, 2023 · article

Auto-populate a variable based on a reference type variable on the form

Define a relationship between two questions in Catalog Builder (for example, fields such as Requested for and Manager) without the need to script. The value of the dependent question is auto-populated when the value of the initial question is selected or changed.

I’ve been waiting for this for longer than I knew ServiceNow existed!

So far, we have had to create ad-hoc Client scripts to handle this common requirement. And there was no perfect solution.

We know the best practice is to use GlideAjax because it’s more efficient.

Efficiency is good, we don’t want our users to waste their valuable milliseconds.

But the syntax of GlideAjax is not very developer-friendly. I can’t blame people for not always following it.

I dreaded it every time, even after creating a generic Script include to handle the server side of it.

Complexity / Friction Response time
GlideRecord ✅ Low ❌ High
getReference ⚠ Medium ⚠ Medium
GlideAjax ❌ High ✅ Low
Auto-populate ✳ None! ✳ Great!

Only in Catalog Builder?

No! It’s also available in the good old classic interface!

And dot-walking is allowed!

Note: You might need to add the tab and fields.

Did you mention better performance?

Full disclosure: I haven’t tested it thoroughly, but it looks good based on the requests and responses.

Only one request is sent to the server even if you have multiple dependent questions.

In my tests, I created one dependent question for Manager’s name and another one for the Employee number.

{"sysparm_dynamic_target_fields": "ee1c8e4247746110985d2646926d43d6,bd49c64e47346110985d2646926d4364",
"sysparm_dynamic_record_id": "6816f79cc0a8016401c5a33be04be441"}

Plus, you only receive the relevant data in the response.

{"result":
{"employee_number":
{"value": "12345", "displayValue": "12345"},
"manager":
{"value": "Joe Employee",
"displayValue": "Joe Employee"}
}
}

Reference

Service Catalog release notes for Utah

The post New in Utah! Auto-populate variable based on a reference appeared first on Rubén Ferrero.

View original source

https://rubenferrero.com/servicenow/auto-populate-variable-reference/