- 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-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 12:15 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 12:19 AM
add your backend name for number and model.
Thanks
dgarad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2025 03:44 AM
Hi @dgarad,
I am having an issue where the model number value is not populating on the form. The model field is a reference field, but the model_number field is not. It is unique for each catalog item, so I’m fetching it directly. However, the value for model_number is not loading on the form.
Could you please guide me on what might be causing this?, Below is my modified code,
Client script: