How to populate the description and picture of the selected record in the catalog item

Gopal14
Tera Contributor

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.

 

1 ACCEPTED SOLUTION

Najmuddin Mohd
Mega Sage

Hi @Gopal14 

NajmuddinMohd_0-1727114932700.png


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.

View solution in original post

5 REPLIES 5

Najmuddin Mohd
Mega Sage

Hi @Gopal14 

NajmuddinMohd_0-1727114932700.png


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.

HI @Najmuddin Mohd

 

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? 

 

Gopal14_0-1727156554241.png

 

 

Gopal14_1-1727156592823.png

 

 

Any changes required?  where exactly description value will populate

HI @Gopal14 ,

Yes, field name with backend value 'description' as type HTML.

Regards,
Najmuddin

 

Thanks @Najmuddin Mohd 

 

For Description is there any other way apart from creating another variable 

 

I want to populate picture also.