Encoded query is not working in catalog client script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 11:50 PM
Hi,
My Encoded query is not working , basically I'm glide recording RITM table to check whether record of same name created in last 30 days exist or not , if this encoded query will not work in client side please help to write script include for the same. below pasting my client script code.
function onSubmit() {
var companyname = g_form.getValue('req_company');
var pacitemname = g_form.getValue('pac_insert');
var grb = new GlideRecord('sc_req_item');
grb.addQuery('u_pac_item', pacitemname);
grb.addQuery('u_requested_for_company', companyname);
grb.addQuery('price', '=', '0.00');
//grb.addEncodedQuery('opened_atONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(O)') //This line of code is not working
grb.query();
if(grb.next())
{
alert('Please select some other PAC Item as you have already selected it earlier for this month');
return false;
}
}
Thanks in Advance
Regards,
Musab

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2016 11:53 PM
Hi Musab,
You can generate the complete query via filter. Please check section 3 here for more info.
Encoded Query Strings - ServiceNow Wiki
Also it is best practice to switch to GlideAjax instead of making GlideRecord calls from client script.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2016 12:14 AM
Encoded query will not work in client side glide record. You will need to replace this with Script include+Glideajax.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2016 12:39 AM
Hi K,
You can still use an encoded query in client-side GlideRecords, if you add it via "gr.addQuery(...)" with a single argument (the encoded query string).
But you're correct in that "gr.addEncodedQuery(...)" is not a supported method for the client-side GR.
Client Side GlideRecord - ServiceNow Wiki
Thanks,
-Brian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-10-2016 12:28 AM
Hi Musab,
You need to convert it to GlideAjax something like this,
function onSubmit() {
var companyname = g_form.getValue('req_company');
var pacitemname = g_form.getValue('pac_insert');
var ga = new GlideAjax('ValidateScript');
ga.addParam('companyname', companyname);
ga.addParam('pracitemname',pacitemname);
ga.getXMLWait();
if(ga.getAnswer()=='true');
{
alert('Please select some other PAC Item as you have already selected it earlier for this month');
return false;
}
}
Create below script include with name ValidateScript
var ValidateScript = Class.create();
ValidateScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
validate: function(){
var companyname =this.getParameter('companyname');
var pacitemname=this.getParameter('companyname');
var grb = new GlideRecord('sc_req_item');
grb.addQuery('u_pac_item', pacitemname);
grb.addQuery('u_requested_for_company', companyname);
grb.addQuery('price', '=', '0.00');
//grb.addEncodedQuery('opened_atONLast 30 days@javascript:gs.daysAgoStart(30)@javascript:gs.daysAgoEnd(O)') //This line of code is not working
grb.query();
if(grb.next())
{
return false;
}
return true;
},
type: 'ValidateScript'
});
Regards
Srinivas