Tim Woodruff
Mega Guru

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”.

find_real_file.png

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/.

Documentation & Download

Comments
Luiz Lucena
Mega Sage

Tried to use that, but is not working. Here is the thread: https://community.servicenow.com/community?id=community_question&sys_id=9627e2aa1b9738d8abbcece7624bcb57

Maybe is not compatible anymore?

Shane J
Tera Guru

Worked for me today in San Diego release.

 

If you're feeding your URL dynamic values (via variables) you have to be very cognizant of your use of single quotes to contain text, and double quotes for building the 'object' because the editor will 'help' you by giving the matching bookend - probably where you don't want it.

Mondiniho
Tera Expert

Is this still available anywhere, when I try the link I just get a "coming soon' page at https://urivars.snc.guru/

_Elisa_
Tera Contributor

@Mondiniho I have found it in this link https://snprotips.com/setting-catalog-item-variables-from-url I hope it helps!

Jeff77
Tera Guru

In reviewing the script, the version of update set I found and am looking at is using the 'unescape' method, which is deprecated.  Does anyone know if there is an new update set version available? Or has anyone tried playing and replacing unescape() with decodeURI() instead?  

Jeff77
Tera Guru

guess you can ignore my question...seems to work with using unescape() call.....

9rb6iw5serg
Tera Explorer

The tool worked perfectly for me, except one detail.. It didn't work for choice "Select Box". It just won't populate and I'm unable to find any information on why? When I test adding it directly with SNUtils, everything works fine, and adding other fields are no problem at all. But the "Select Box" just gets marked red. Tried adding false values as well directly in the form, it creates a new value that isn't related to anything, but via the variable set NOTHING happens

jcmings
Mega Sage

Just posting to say that I love this! I've used this on multiple projects now. Thank you! 

 

For those that need the link: https://snprotips.com/setting-catalog-item-variables-from-url

 

Version history
Last update:
‎04-04-2019 10:54 AM
Updated by: