Adding parameters in URL

JPSS
Tera Contributor

When a user is clicking a url from external application then it should redirect to a catalog item in servicenow with short description 'SAP'

 

 

I tried passing paramenters as below but its not working .

 

Can anyone helo me please

https://{INSTANCE NAME}.service-now.com/sp?id=sc_cat_item&sys_id=482c8a621bdb0510ccbb6202b24bcb2a&sysparm_variables="short_description":"SAP"

9 REPLIES 9

The easiest way is when you can pass variables through a URL using query parameters. A query parameter is a key-value pair that is added to the end of a URL.

For example, if you have a variable called "short_description" that contains the value "SAP", you can pass it through the URL using the following syntax:

https://{INSTANCE NAME}.service-now.com/sp?id=sc_cat_item&sys_id=482c8a621bdb0510ccbb6202b24bcb2a&short_description=SAP

JPSS
Tera Contributor
  •  

In that case:

  1. Create a UI page in ServiceNow, this page will be used to redirect the user to the catalog item page and also filter the catalog items by short description.

  2. In this UI page, you can retrieve the short_description variable from the URL using the following JavaScript code:

 

var short_description = getParameterByName('short_description');

 

 

Use this variable to filter the catalog items by short description using the following JavaScript code:

 

var catalogItems = g_form.getReference('catalog_item', filterCatalogItems);

function filterCatalogItems(catalogItems) {
    catalogItems = catalogItems.filter(function (item) {
        return item.short_description == short_description;
    });
    // Do something with the filtered catalog items
}
​

 

After filtering the catalog items, you can use the JavaScript to redirect the user to the catalog item page 

 

if(catalogItems.length>0){
    var catalog_sys_id=catalogItems[0].sys_id;
    window.location.href = '/sp?id=sc_cat_item&sys_id='+catalog_sys_id;
}else{
    //show a message that the item not found.
}
​

 

 

-O-
Kilo Patron
Kilo Patron

SN Pro Tips has a solution you can download and install or copy into your instance.

It is a variable set that one can add to any Catalog Item.

Will parse the sysparm_variables URL parameter in an onLoad Catalog Client Script and will set fields to values defined in that parameter.

-O-
Kilo Patron
Kilo Patron

Just to clarify, there is no OOB solution to send variable values through URL parameters, like there is for forms.