- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 07:38 AM
Hello, we have a requirement to fill in a variable on the Employee Center view of a catalog item via the URL. I know there are many posts about this topic but after reading them, I still do not understand what I need to do to get this to work.
To explain the requirement fully, we have a catalog item to update business applications in ServiceNow. Quarterly via flow designer, an email is sent to the business application owner. That email contains a URL to the catalog item and we want the URL in that email to fill in the Application Name reference field of the catalog item with the business application. The Application Name reference field references the cmdb_ci_business_app table.
From the other posts I've read, the way to do this is to have a catalog client script as well as a URL containing the parameter of the variable you wish to fill. My knowledge of scripting is lacking, so any assistance with this is very appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:38 AM - edited 11-30-2023 09:38 AM
My BAD. I missed to check UI TYPE to ALL on catalog client-script to make it run on all platforms, not only on Service Catalog.
After that once you update the sys-id of catolog item in below url with appropriate URL Params, it should work -
/esc?id=sc_cat_item&sys_id=$CAT-SYS-ID$&email=hsb&justification=thisistesting
Should work as it worked on my PDI.
Do mark this response as CORRECT / HELPFUL as it would help others & will help me as well to keep writing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 07:56 AM - edited 11-30-2023 07:59 AM
So let me clear what I understood -
As soon as someone opens the URL, variables on the catalog item should get filled up automatically, is that correct ?
Also do share one sample of the URL which you are planning to provide them with all the query-parameters in it which will be used to populate variables data e.g. https://example.com/test/api?parm1=test123&parm2=test234 etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 07:59 AM
That's correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 08:32 AM - edited 11-30-2023 08:34 AM
I tried it on my personal instance & was able to fetch URL parms & set 2 text variables data. You can do following -
1. Create an onLoad catalog client script on your Catalog Item
2. Configure it as similar to following screenshot -
function onLoad() {
var email = getParameterValue('email');
var justification = getParameterValue('justification');
if(email){
g_form.setValue('please_provide_the_preferred_email_alias',email);
}
if(justification){
g_form.setValue('business_justification',justification);
}
}
function getParameterValue(name) {
var url = top.location.href;
var value = new URLSearchParams(url).get(name);
if (value) {
return value;
}
}
3. Make sure you are updating the parameters name in the script as per your URL & also the variable's backend names. In your case you are utilizing 'Application Name' which seems like a 'Choice' field so you should be passing the backend value of whatever choice you want to set to this variable.
My URL format is as follows -
4. After that as soon as you load the catalog item with your custom URL, it will run the script onLoad & pickup data from URL & set it on variables.
It should be enough, if it doesn't work most probably you are missing some minor details in your script.
Do mark it as CORRECT / HELPFUL as it help others & will motivate me to keep writing as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 09:25 AM
Thanks!! It now fills in the Application Name field correctly but I'm struggling to get the URL to point to the catalog item on the Employee Portal.
This link fills the variable on the Service Catalog: https://<instance>.com/com.glideapp.servicecatalog_cat_item_view.do?v=1&sysparm_id=b27fbf591b3e75505...
Next, I'm trying to get this URL working to go to the catalog item on the Employee Center: https://<instance>.com/esc?id=sc_cat_item&table=sc_cat_item&sysparm_id=b27fbf591b3e755051582023604bc...
It goes to the correct catalog item but doesn't fill the variable if I change "sysparm_id" to just "sys_id", so I think I have the URL formatting messed up.
This is the catalog client script I ended up using.
function onLoad() {
var businessApp = getParameterValue('application');
g_form.setValue('application',businessApp);
}
function getParameterValue(id) {
var url = top.location.href;
var value = new URLSearchParams(url).get(id);
if (value) {
return value;
}
}