Query table data to display in a Service Catalog field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2019 11:05 PM
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:
As the result, nothing is displayed...
What part do i write wrong?? Could anyone give me some tips??
Thanks in advance.
Lit
- Labels:
-
Best Practices
-
Instance Configuration

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2019 11:16 PM
Hi
It is not a best practise to do a Glide Record in client scripts. Try using a script include which serves the purpose of what you're trying to do.
Check the below link :-
https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side
Mark my answer helpful or correct if my response helped you solve your doubt.
Regards,
Omkar Mone
www.dxsherpa.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 12:41 AM
Now I am trying to create script include as advised by Omker,
however, I am super new to ServiceNow and javascript (i mean, to everything, honestly...)
this "getParameter" thing in script include, should I give the column name which serves as the key when filtering data?
But there is another line which states;
gr.addQuery('u_item_name', target); (the same column name is set twice...?)
var setUnitPrice = Class.create();
setUnitPrice.prototype = {
getUnitPrice : function() {
var target = this.getParameter('u_item_name');
var gr = new GlideRecord('u_uniform_item_master');
gr.addQuery('u_item_name', target);
gr.query();
if(gr.next()){
g_form.setValue('u_item_unitprice_men',gr.getDisplayValue("u_item_price"));
return gr.u_item_price;
}
return '';
},
type: 'setUnitPrice'
};
Client script, i am totally lost and not yet achieved to create...
I appreciate so much if anyone could help me out 😉
Lit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 01:30 AM
Hi Lit,
Try the below codes.
client script code,
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);
}
Script include code,
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'
};
If my reply has helped you,Kindly click the Helpful button.
If my reply is the answer you were looking for, Kindly click the Accepted Solution button.
Thanks,
Priya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2019 02:00 AM
Thank you so much, Priya,
it seems it's almost done.
Just a popup message says the value is null...
The table has records, all the variable names and column names are correct.
I am very grateful if you could give me some advice about possible causes.
Cheers,
Lit