Encoded Query String not working

mark141230
Tera Expert

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!

 

11 REPLIES 11

DirkRedeker
Mega Sage

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

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.

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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.