- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Problem Statement: Many a times there is a need to grab parameters from URL. This could be required at table form load or catalog item load and either in Global scope or custom scope application when redirection happened.
Use Case:
1) You want to redirect from incident record to catalog item and would like to pass few parameters such as incident short description, incident caller.
2) Another common use case would be creating requests from incidents. In this case you would require to pass some information such as Caller and set it as "Requested For".
Consider you have a Service-now.com URL that looks like this…
https://instanceName.service-now.com/incident.do?sys_id=-1&sysparm_query=active=true&sys_myParameter=hello
There would be an onLoad client script to get the parameter value and set in respective variables.
There are multiple scenarios wherein this would be required as below. Following are the 4 possible scenarios I could think of.
Scope: Global
a) Table/Form Load - Client Script
b) Portal - Catalog Client Script
Scope: Custom
a) Table/Form Load - Client Script
b) Portal - Catalog Client Script
There are a number of solutions on the question but very few work in all the above scenarios considering scoped app and portal view. Considering document and window object leads to some issue in portal and scope app; I thought to write a blog with a script which handles all the above 4 scenarios
Below is the script which would work in all the above 4 cases:
Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var glideURL = new GlideURL();
glideURL.setFromCurrent();
var id = glideURL.getParam("sysparm_id"); // give here the parameter name
}
Thanks for reading the blog and do provide your inputs/suggestions if any.
Hope you find this article helpful. Don’t forget to Mark it Helpful, Bookmark.
Thanks,
Ankur Bawiskar
- 2,423 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
