Encoded Query String not working
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 08:32 PM
Hi Everyone,
Seeking your help please. I have created a notification triggered by an event. I intended to schedule the job to run daily.
Unfortunately it seems that my script where unable to grab the records using the query I provided which is got after I filter the record whose end date is today. Please see my script below:
var rec = new GlideRecord('resource_plan');
rec.addEncodedQuery('state=3^end_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday');
rec.query();
while (rec.next()){
gs.eventQueue("resourceplanend.now", rec);
}
Thanks in Advance!
- Labels:
-
Script Debugger
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 09:22 PM
Hi
Did You try this condition in a list before.
I recommend to open the list of the "resource_plan" table in the classic UI and open the left top filter/condition builder.
Then enter your condition there until it returns the records you want to.
Copy the condition to your script.
Test your script first in "scripts background" to see, if you get the expected results.
For your scheduled job, check if it is running as a user with sufficient access rights.
Let me know if that answered your question and mark my answer as correct and helpful
BR Dirk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 09:55 PM
Yes Dirk, derived that query string in the list but when I tried to run it in the background nothing returns. That is why is a puzzle to me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 10:28 PM
Hi Mark,
try forming the query on the table; copy the query from there and use it as encoded query
That is the safest way; also try adding row count log
Also your eventQueue() doesn't have 3rd parameter; have you set users/groups to whom email should go at notification level itself
var rec = new GlideRecord('resource_plan');
rec.addEncodedQuery('state=3^end_dateONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday');
rec.query();
gs.info(rec.getRowCount());
while (rec.next()){
gs.eventQueue("resourceplanend.now", rec);
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2020 10:35 PM
Hi Ankur,
The query string I provided was derived from the table I queried. In the list it returns 1 record which is expected then in the backgroundscript nothing returns.