GlideAJAX ScriptInclude question

Dave_p
Giga Guru

Hi,

I am unable to get the proper output once I am completed with the script. Kindly help.

 

1.png

 

function onLoad() {
   
   var sys = g_form.getUniqueValue();
   var ga = new GlideAjax('onLoad_Owner_Class');
   ga.addParam('sysparm_name', 'onLoad_Owner_Function');
   ga.addParam('sysparm_id', sys);
   ga.getXML(callBackFunction);
   function callBackFunction(response){
	var answer = response.responseXML.documentElement.getAttribute('answer');
	g_form.setValue('owner', answer);
   }
   
}

 

ScriptInclude

2.png

 

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

	onLoad_Owner_Function: function(){
		var keyOwner = this.getParameter('sysparm_id');
		var gr = new GlideRecord('sc_cat_item');
		gr.addQuery('sys_id', keyOwner);
		gr.query();
		if(gr.next()){
			return gr.owner;
		}
	},

    type: 'onLoad_Owner_Class'
});

 

4.png3.png

 

Regards

Suman P.

1 ACCEPTED SOLUTION

Dave_p
Giga Guru

Hi,

I am sorry, I made a mistake, wherein owner is a reference variable in sc_cat_item table, and I have been using gr.owner, I should have used getDisplayValue. Her is the correct code.

 

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

	onLoad_Owner_Function: function(){
		var keyOwner = this.getParameter('sysparm_id');
		var gr = new GlideRecord('sc_cat_item');
		gr.addQuery('sys_id', keyOwner);
		gr.query();
		if(gr.next()){
			return gr.getDisplayValue('owner');
		}
	},

    type: 'onLoad_Owner_RU'
});

 

Regards

Suman P.

View solution in original post

4 REPLIES 4

Dave_p
Giga Guru

Hi,

I am sorry, I made a mistake, wherein owner is a reference variable in sc_cat_item table, and I have been using gr.owner, I should have used getDisplayValue. Her is the correct code.

 

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

	onLoad_Owner_Function: function(){
		var keyOwner = this.getParameter('sysparm_id');
		var gr = new GlideRecord('sc_cat_item');
		gr.addQuery('sys_id', keyOwner);
		gr.query();
		if(gr.next()){
			return gr.getDisplayValue('owner');
		}
	},

    type: 'onLoad_Owner_RU'
});

 

Regards

Suman P.

Robert H
Mega Sage

Hello @Dave_p ,

 

I copied your Client Script and Script Include to my PDI and it works fine. The field gets populated with the Catalog Item owner.

Does it literally return the string "Record not found" on your end?

 

Regards,

Robert

Hi @Robert H,

 

Actually what happened is that there is exactly same class name already existing. So, it was taking that class instead of what I have written now. I have pasted the working code already. Owner is a reference variable referencing User table, unfortunately, my mistake I literally took it as Single line text variable and used object.owner which should have been object.getDisplayValue('owner'). I updated it, and it started working. Thank you for looking into it.

 

Regards

Suman P.

Hello @Dave_p ,

 

Ok, in this case please mark your question as answered so that community members are aware and don't spend time investigating.

 

Regards,

Robert