How we can set the variables on catalog item form from UI action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 08:10 AM
We have one catalog item where users are filling some variables and submitting the request, Once it is submitted one task will be generated for that request and on same task form we have one UI action, Whenever user clicks on UI action another catalog item form opens up in new tab and there we want to set the variable values from the task where we have UI action available.
e.g - User will raise the 'ABC' catalog item and one task will be generated for 'ABC' catalog item, On that task we have one UI action 'Create Request'. Whenever user clicks on it new catalog item form 'PQR' will open and there we want to set the variable values from 'ABC' catalog item task.
How we can achieve this.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 08:25 AM
another catalog item form opens in new tab
So you need to redirect the user and pass the values in URL and then use onLoad catalog client script on that redirected catalog item and populate it
check this link and it will solve your query; but please enhance it as per your requirement
http://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/
3 Ways to Populate Values in ServiceNow via the URL
Steps
1) make your UI action client side or server side and include the form fields values or variables values in URL and include as parameter
2) then parse and populate
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-11-2023 09:16 AM
Hello @Peter Wood
Can you try below code..!!
Step 1 : Create UI action on Catalog Task Table (You can set visibility depending upon your requirement)
Script :
/* get teh values of variables */
function redirectURL(){
//get the Values of variable from sc_task variables
var var1 = g_form.getValue('variables.my_variable_1');
var var2 = g_form.getValue('variables.my_variable_2');
/* Create custom URL */
//sys_id of catalog item where we want to redirect
var url = "https://dev1127373.service-now.com/sp?id=sc_cat_item&sys_id=fe0ebd1cc311b110ab85241ce0013175" + '&sysparm_var1=' + var1 + '&sysparm_var2=' + var2;
g_navigation.open(url, '_blank');
}
Step 2 : Write onLoad client script on catalog item which we have redirected to.
function onLoad() {
//get URL
var gUrl = top.location.href;
/* Split the URL and get Variables values */
var variable1 = gUrl.split('&')[2].split('=')[1];
var variable2 = gUrl.split('&')[3].split('=')[1];
/* Use your variable name */
g_form.setValue('get_variable_1', variable1);
g_form.setValue('get_variable_2', variable2);
}
Step 3 : Click on UI action created on catalog task
It will redirect you to Catalog form with variable value set on form
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates