Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Glide Ajax script to get a record details on catalog item variable

Bindhu1
Tera Contributor

Hi All , 
I am trying to fetch the solution record detail on cat item variable , kindly help me with the code.
I have 2 question on form:
1st Q. refer to Solution table[cmdb_ci_service]

2nd Q. is multiline text
Based on the solution select in 1st Q , 2 Q should give selected solution details eg:
Name:
Support group:
etc.

Bindhu1_0-1710263456305.png

 

Thanks

1 ACCEPTED SOLUTION

swathisarang98
Giga Sage

Hi @Bindhu1 ,

 

You can create a on change client script and script include.

Q1. Reference field -> cmdb_ci_service

Q2. Multi line text -> readonly

 

Please change the backend names accordingly,

 

Onchange client script:

swathisarang98_0-1710267492134.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var sysId = g_form.getValue('services');

   var ga = new GlideAjax('getSolutionDetail');
   ga.addParam('sysparm_name','getSolution');
   ga.addParam('sysparm_id',sysId);
   ga.getXML(getResponse);
   
}

function getResponse(response){
	var ans = response.responseXML.documentElement.getAttribute('answer').split(',');
	var name = ans[0];
	var group = ans[1];
	g_form.setValue('solution', "Name: " + name + '\n' + "Support Group: " + group);

}

 

 

Script Include:

Make it client callable

swathisarang98_1-1710267573707.png

 

var getSolutionDetail = Class.create();
getSolutionDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getSolution: function(){
		var sysId = this.getParameter('sysparm_id');
		var serviceName = new GlideRecord('cmdb_ci_service');
		serviceName.addQuery('sys_id',sysId);
		serviceName.query();
		var arr =[];

		if(serviceName.next()){
			arr.push(serviceName.name.toString());
			arr.push(serviceName.support_group.getDisplayValue());
			
		}
		return arr.toString();
	},

    type: 'getSolutionDetail'
});

 

 

Result:

swathisarang98_2-1710267657457.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

2 REPLIES 2

swathisarang98
Giga Sage

Hi @Bindhu1 ,

 

You can create a on change client script and script include.

Q1. Reference field -> cmdb_ci_service

Q2. Multi line text -> readonly

 

Please change the backend names accordingly,

 

Onchange client script:

swathisarang98_0-1710267492134.png

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }

   var sysId = g_form.getValue('services');

   var ga = new GlideAjax('getSolutionDetail');
   ga.addParam('sysparm_name','getSolution');
   ga.addParam('sysparm_id',sysId);
   ga.getXML(getResponse);
   
}

function getResponse(response){
	var ans = response.responseXML.documentElement.getAttribute('answer').split(',');
	var name = ans[0];
	var group = ans[1];
	g_form.setValue('solution', "Name: " + name + '\n' + "Support Group: " + group);

}

 

 

Script Include:

Make it client callable

swathisarang98_1-1710267573707.png

 

var getSolutionDetail = Class.create();
getSolutionDetail.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getSolution: function(){
		var sysId = this.getParameter('sysparm_id');
		var serviceName = new GlideRecord('cmdb_ci_service');
		serviceName.addQuery('sys_id',sysId);
		serviceName.query();
		var arr =[];

		if(serviceName.next()){
			arr.push(serviceName.name.toString());
			arr.push(serviceName.support_group.getDisplayValue());
			
		}
		return arr.toString();
	},

    type: 'getSolutionDetail'
});

 

 

Result:

swathisarang98_2-1710267657457.png

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

This works as expected. I truly appreciate your assistance and the effort you've put in. Thank you so much for your help.