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  

Query table data to display in a Service Catalog field

L_10
Kilo Contributor

Hi Community,

I have a question about Service Catalog variables.

 

<field A> A user selects an item name (in the image below, the variable name is "u_item_name_men")

<field B> A user selects whether or not s/he wants the item new or second hand ("u_item_newreuse_men")

             (this is not yet described in the code below, just wanting to add in the future)

<field C> Unit price of A item depending on A&B's selection ("u_item_unitprice_men")

A, B, and C are in the same variable set "u_vset_men".

The table I want the data to reference is "u_uniform_item_master".

The Catalog Client Script is like the image below:

find_real_file.png

As the result, nothing is displayed...

What part do i write wrong?? Could anyone give me some tips??

Thanks in advance.

Lit

19 REPLIES 19

Which value gives you null popup message?

 

Thank you for your reply, Priya.

 

When I choose an item name, it comes up. 

find_real_file.png

Hi 

Can you paste your Script include and Client script code?

L_10
Kilo Contributor

Hi Omker,

sure. Please check below.

 

Script Include:

var setUnitPrice = Class.create();
setUnitPrice.prototype = {
	getUnitPrice : function() {
		var target = this.getParameter('sysparm_item_name');
		var gr = new GlideRecord('u_uniform_item_master');
		gr.addQuery('u_item_name', target);
		gr.query();
		if(gr.next()){
			return gr.u_item_price;
		}
	},
	type: 'setUnitPrice'
};

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading || newValue == '') {
		return;
	}
	
	//Type appropriate comment here, and begin script below
	var target = g_form.getValue('u_item_name_men');
	var ga = new GlideAjax('setUnitPrice');
	ga.addParam('sysparm_name', 'getUnitPrice');
	ga.addParam('sysparm_item_name', target);
	ga.getXML(setPrice); function setPrice(response)
	{
		var answer = response.responseXML.documentElement.getAttribute("answer");
		alert(answer);
		g_form.setValue('u_item_unitprice_men',answer);
	}
	
}

The client script is in the variable set "u_vset_men".

The  variable "u_item_name_men" (also created under the same variable set) is set in variable name field.

Hi ,

So here i see a problem. Do one thing,

Create a new Script include with Client Callable checkbox check while creating the Script include.

 

It would work.

 

Check the below ss :-

find_real_file.png

Mark correct if it helped.

 

Regards,

Omkar Mone.

www.dxsherpa.com