- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2025 10:06 PM
Hi,
I have created a "model number" variable and its corresponding value as part of a variable set, along with another variable called "model." This setup is applied to multiple catalog items, each with a unique value. I’ve used a Script Include and Client Script to load the variable field along with its value. However, while other variables ("model" and its value) populate correctly when entering the form, the model number variable is not populated with its value.
Can someone help me identify why the model number is missing, and guide me on how to properly load the model number?
Below is the code:
Client Script:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2025 11:00 PM
change code as below and try.
Client Script:
function onLoad() {
var util = new GlideAjax("ServiceCatalogItem");
var rec = g_form.getUniqueValue();
util.addParam("sysparm_name", 'getCatItemModel');
util.addParam("sysparm_cat_id", rec);
util.getXML(callBack);
var answer;
function callBack(response) {
answer = response.responseXML.documentElement.getAttribute("answer");
var sepAnswer = answer.split('$');
g_form.setValue("u_model", sepAnswer[0]);
g_form.setValue("u_model number", sepAnswer[1]);
}
}
Script Include:
var ServiceCatalogItem = Class.create();
ServiceCatalogItem.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCatItemModel: function() {
var modelDetails='';
var sys_id = this.getParameter('sysparm_cat_id');
var item = new GlideRecord('sc_cat_item');
item.addQuery("sys_id", sys_id);
item.query();
if (item.next()) {
return modelDetails.item.model.name+','+modelDetails.item.model.number;
//model number field should also loaded with its value
} else {
return false;
}
},
type: 'ServiceCatalogItem'
});
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 07:34 PM
model_number is correct backend table field. it may be u_model_number.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2025 11:17 PM
you can achieve this without scripting using Auto populate feature starting from Utah release
Auto-populate a variable based on a reference type variable (Utah)
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
02-03-2025 03:48 AM
Hi @Ankur Bawiskar ,
Thank you for your response. The fields are read-only. I need for non-reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 03:50 AM
the auto populate feature is to bring data from referenced table
Did you explore that?
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