Set Catalog Variables from URL Params (Free tool)
I've had this question come up over and over again in my career: "How do we populate variables on a catalog item or record producer, from the URL?"
There are a couple of ways to do this, but often you'll see one-off solutions that require custom code for each and every catalog item, which also means that you have to know in advance, when designing the catalog item, what variables might be specified by URL, and how to populate them.
I got tired of re-engineering the same basic solution over and over again, so I built the following little generalized tool: This tool adds to your system, a Variable Set. This variable set contains a catalog client script, but no actual variables (this is expected). The variable set is called “Parse sysparm_variables URI param”.
Once you’ve added the variable set to a given catalog item, you can populate any one or more variables in that catalog item, simply by manipulating the URL.
Simply add a single URI parameter (sysparm_variables) to the URL for any catalog item, and set its value to a JSON-encoded string, with each variable you'd like to populate, and its value.
Example:
https://INSTANCE.service-now.com/sp?id=sc_cat_item&sys_id=b42ad20a3738630090b68cf6c3990e5b&sysparm_variables={"example_user_reference":"5137153cc611227c000bbd1bd8cd2005"}
You can specify any number of variables and values in this JSON object, as long as you encode any illegal characters (which most browsers will do for you automatically).
Once you've added the "variable set" containing the necessary script to a catalog item, the exact same sysparm_variables URI parameter, will work for URLs pointing to both the portal, and the classic UI:
https://INSTANCE.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=b42ad20a3738630090b68cf6c3990e5b&sysparm_variables={"example_user_reference":"5137153cc611227c000bbd1bd8cd2005"}
You can find additional detailed documentation, and a link to download the tool for free at the below link, or at http://urivars.snc.guru/.
https://www.servicenow.com/community/developer-articles/set-catalog-variables-from-url-params-free-tool/ta-p/2325359