- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2025 05:51 AM
For suppose If I open a form of a catalog item IPhone which is in the category Mobile. Now I want to populate the value Mobile in the variable which I created for that catalog item IPhone and when it comes to its type - maybe it is any type.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2025 06:28 AM - edited 09-29-2025 06:31 AM
Hi @ramasatyasa,
Using this code, you can populate the catalogue item category. in catalog item variable
1) open the catalogue item variable from and in default value paste this code.
javascript: current.cat_item.category.getDisplayValue();
output
If my response helped you, please mark it as the correct answer and close the thread. This way, others in the community can benefit too.
Regards,
TejasSN_LogicX
ServiceNow Developer | HackaNow Finalist | Community Contributor
📧tejas.adhalrao11@gmail.com
🔗LinkedIn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2025 08:46 PM
Could you explain this:
current.cat_item.category.getDisplayValue();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2025 04:56 PM
Hi @ramasatyasa,
We have a catalogue item variable record. In that record we have a catalogue item reference field.
so
current →
Refers to the current variable record.current.cat_item →
Points to the catalogue itemthat this request item belongs to. gets the value of the catalogue itemcurrent.cat_item.category →
From the catalogue item record, it fetches the category (another reference field pointing to it). get value of the catalogue item category by dot walking..getDisplayValue() →
Instead of returning the raw sys_id, it returns the readable name (label) of that category. It's showing category display value/frontend value (not the sys_id)
And we are setting the variable's default value here. using this code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2025 07:18 AM
Hi @ramasatyasa
You can populate the variable on form load using a Catalog Client Script (type: onLoad). Since the Catalog Item belongs to a Category (like Mobile), you can fetch that category and set it in your variable. Example:
function onLoad() {
// Replace 'u_category_variable' with your variable name
var catVar = g_form.getGlideUIElement('u_category_variable');
if (catVar) {
// Get Catalog Item sys_id from URL
var itemSysId = g_form.getParameter('sys_id');
// Call a GlideAjax / getReference to fetch the category
var gr = new GlideRecord('sc_cat_item');
if (gr.get(itemSysId)) {
var cat = gr.category.getDisplayValue();
g_form.setValue('u_category_variable', cat);
}
}
}
The Catalog Item (like iPhone) is linked to a Category (like Mobile) through the sc_cat_item table.
Using a client script, you can fetch that Category and set it to your custom variable.
