How to populate incident number in service catalog variable? When ever click UI action button
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 07:34 PM
Hi experts,
Whenever click an UI action button the INC number populate on catalog Item view
The below code working but not set value on catalog form view
UI Action
var ritm = new GlideRecord("sc_cat_item");
ritm.addEncodedQuery("name=Test item");
ritm.query();
while (ritm.next()) {
ritm.variables.number = current.number;
url="https://dev67613.service-now.com/com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=35ec533a2f101110617acfedf699b635&v=1";
action.setRedirectURL(url);
gs.addInfoMessage(ritm.number);
current.update();
}
Can u please help on that
Thanks,
Surya

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 07:41 PM
Hi check the below thread for your answer
https://community.servicenow.com/community?id=community_question&sys_id=9dbf366ddb58dbc01dcaf3231f9619a0
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-31-2022 07:43 PM
Hi,
Suggestion from my end would be to follow below steps to populate Incident number on your catalog form:
1. Create a UI Action on your Incident table and use the script as mentioned below in your UI Action:
var url = '/sp?id=sc_cat_item&sys_id=3f1dd0320a0a0b99000a53f7604a2ef9&sysparm_number='+ current.number;
action.setRedirectURL(url);
Replace your Catalog Item sys id in above code.
So when you will click on the button on your Incident form it will form the URL with the value which you need and then you need to follow below steps:
1) Write a On Load Catalog Client Script on your Catalog Item and use the script as below:
function onLoad() {
//Use the 'getParameterValue' function below to get the parameter values from the URL
var num = getParameterValue('sysparm_number');
if (user) {
g_form.setValue('Variable Name', num); // Replace "Variable Name" with your variable where you want to populate the number value
}
}
function getParameterValue(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(top.location);
if (results == null) {
return "";
} else {
return unescape(results[1]);
}
}
This way you can add your other variable as well. This is working for me as shown below:
Result: This is just an example which I did for other fields to auto populate it on catalog form.
Hope this helps. Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke