validation of addEncodedQuery()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 08:14 AM
Hi ,
i had requirement in email inbound script.
i need to check whether my encoded query is valid or not
var gr=new GlideRecord('sys_user');
gr=gr.addEncodedQuery(query);
gr.query();
i need to check if this is not going to an error when query is not valid
when query is 'user=abel.tutor' there 'll not be generation of result
suggest me here how can i validate addEncodedQuery(query)..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 08:30 AM
Hi Akash
To verify if query has records,You can use hasNext() or next() with your gr object
Example:
var gr=new GlideRecord('sys_user');
gr=gr.addEncodedQuery(query);
gr.query();
while(gr.next())
{
// we can use gr to access the value of each record queried.
//do something
}
or
var gr=new GlideRecord('sys_user');
gr=gr.addEncodedQuery(query);
gr.query();
if(gr.hasNext()) //verifying if your gliderecord has any records.
{
//do something
}
hasNext() : hasNext() method returns true if iterator have more elements.
next() : next() method returns the next element and also moves to the next element.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 08:53 AM
Hi Voona,
Sorry ,I'm not checking for this..after querying only you'll get to know if there's any records present in your answer,but what i need is before going to next step say gr.query() and so on..I need to check whatever i'm giving in "addEncodedQuery(query);" is valid or not,because if we give invalid query for addEncodedQuery(query); ,the next step wont be executed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 09:08 AM
Hi
If you want to check whether the query is valid or not, then better tot use GlideQuery instead of GlideRecord.
once check this blog -
GLIDEQUERY PART 1
If my response is helpful, then Please mark as Correct Answer/Helpful.
Please check and let us know.
Thanks 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2022 06:28 PM
Hi
once check this link -
ServiceNow Encoded Query validation
If my response is helpful, then Please mark as Correct Answer/Helpful.
Please check and let us know.
Thanks 🙂