- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 10:19 AM
Hi Team,
How to populate the description and picture of the selected record in the catalog item
EX:
I am having catalog item in that I am having a reference field(cmdb_hardware_product_model), when we select any record in that refence field, that record description and picture should populate below of the reference field.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 11:17 AM - edited 09-23-2024 11:17 AM
Hi @Gopal14
On selection of a Catalog, you need write an On change client script and call GlideAjax to the script include to get the value.
Client script:
Type: On change
Variable: hardware_model
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.clearValue('description'); // Clear the value when another model is selected
var ga = new GlideAjax('HardwareModel'); // Calling the script include
ga.addParam('sysparm_name','description'); // calling the method
ga.addParam('sysparm_model',newValue);
ga.getXML(answer);
function answer(response){
var value = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('description',value); // populating the description
}
}
Script Include:
Client callable : True
Name: HardwareModel
var HardwareModel = Class.create();
HardwareModel.prototype = Object.extendsObject(AbstractAjaxProcessor, {
description : function() {
var model = this.getParameter('sysparm_model'); // get the sys_id from the script
var gr = new GlideRecord('cmdb_hardware_product_model');
gr.addQuery('sys_id',model);
gr.query();
if(gr.next()){ // if sys_id found, return the description
return gr.description;
}
},
type: 'HardwareModel'
});
If this information helps you, Kindly mark this post as helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 11:17 AM - edited 09-23-2024 11:17 AM
Hi @Gopal14
On selection of a Catalog, you need write an On change client script and call GlideAjax to the script include to get the value.
Client script:
Type: On change
Variable: hardware_model
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
g_form.clearValue('description'); // Clear the value when another model is selected
var ga = new GlideAjax('HardwareModel'); // Calling the script include
ga.addParam('sysparm_name','description'); // calling the method
ga.addParam('sysparm_model',newValue);
ga.getXML(answer);
function answer(response){
var value = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('description',value); // populating the description
}
}
Script Include:
Client callable : True
Name: HardwareModel
var HardwareModel = Class.create();
HardwareModel.prototype = Object.extendsObject(AbstractAjaxProcessor, {
description : function() {
var model = this.getParameter('sysparm_model'); // get the sys_id from the script
var gr = new GlideRecord('cmdb_hardware_product_model');
gr.addQuery('sys_id',model);
gr.query();
if(gr.next()){ // if sys_id found, return the description
return gr.description;
}
},
type: 'HardwareModel'
});
If this information helps you, Kindly mark this post as helpful and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 10:43 PM - edited 09-23-2024 10:45 PM
I have created both script include and client script same way which you have provided.
Do I need to create another variable to populate description value?
Any changes required? where exactly description value will populate
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 11:08 PM
HI @Gopal14 ,
Yes, field name with backend value 'description' as type HTML.
Regards,
Najmuddin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2024 11:12 PM
Thanks @Najmuddin Mohd
For Description is there any other way apart from creating another variable
I want to populate picture also.