- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 11:20 PM
How to get the catalog item name in a field Item form?
I need to load name of the item in the "Item Name" field, Ex: In the above screen shot, i need to have 'Test Item' value in Item name.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 11:44 PM
Hi Swathi,
I think you can have onLoad catalog client script, get the window url which should contain the catalog item sys_id, query the maintain item table with this sys_id and populate the item name in that variable.
var windowUrl = window.location.href;
// it should print something like this.
var rec_sys = getParmVal('sysparm_id'); // this contains the sys_id
if(rec_sys != null) {
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id',rec_sys);
gr.query();
if(gr.next()){
g_form.setValue('variable_name', gr.name)
}
}
function getParmVal(name){
var url = document.URL.parseQuery(); // this also gives the window url
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 11:32 PM
Hi Swathi,
For this, i belive you have to use variable editor to get the variable field on request item form.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 11:44 PM
Hi Swathi,
I think you can have onLoad catalog client script, get the window url which should contain the catalog item sys_id, query the maintain item table with this sys_id and populate the item name in that variable.
var windowUrl = window.location.href;
// it should print something like this.
var rec_sys = getParmVal('sysparm_id'); // this contains the sys_id
if(rec_sys != null) {
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id',rec_sys);
gr.query();
if(gr.next()){
g_form.setValue('variable_name', gr.name)
}
}
function getParmVal(name){
var url = document.URL.parseQuery(); // this also gives the window url
if(url[name]){
return decodeURI(url[name]);
}
else{
return;
}
}
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2017 11:47 PM
Hi Swati,
We had a similar requirement and here is the code we built. This will populate the name of the item in a specific field, in our case short description.
var sysID = $('sysparm_id').value;
var catalogName = new GlideRecord('sc_cat_item_producer');
//catalogName.addEncodedQuery(encQuery);
catalogName.addQuery('sys_id',sysID);
catalogName.query();
while(catalogName.next())
{
g_form.setValue('Short_Description',catalogName.name); // BACKEND NAME OF THE FIELD ITEM_NAME
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-12-2017 12:05 AM
Hi Swathi,
Since you have marked the answer as correct, please mark it as helpful and hit like. Thanks in advance.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader