Scheduled Jobs, Events and Encoded Query

plowe
Mega Contributor

Hi,

I'm trying to setup a scheduled job to find Problems which meet a criteria and trigger an event which will fire a notification.   I've tried to use an Encoded Query to apply the filter but I can't get it to work.   Am I missing something here because as far as I can tell this should work. It's the encoded query that isn't working but this is taken directly from list view.

Any help appreciated

My code is

// This scheduled job runs every morning and looks at all Problems which are associated with an MI

// Where these exist it checks that they havent had a post mortem and whether it has been 7 days since a reminder was sent

// where this is the case it triggers the event rb.problem.mipm and updates the reminder date to 7 days in the future

// Note that u_post_mortem_reminder_sent is not the sent day but actually the date the next reminder is due.

var gr = new GlideRecord('Problem');

gr.addEncodedQuery("u_mi_referenceISNOTEMPTY^u_mi_post_mortem_submitted=false^u_mi_post_mortem_reminder_sentONToday@javascript:gs.daysAgoStart(0)@javascript:gs.daysAgoEnd(0)");

gr.query();

gs.log("PL - Rows found" + gr.getRowCount());

while (gr.next()) {

gs.eventQueue("rb.problem.mipm",gr);

}

I'm getting the following error:

java.lang.NullPointerException

Caused by error in <refname> at line 6

1 ACCEPTED SOLUTION

oharel
Kilo Sage

Hi Peter,



Basically, seems fine to me.


Just a thought:


1. change Problem to problem


2. try: var encQuery = '<your query here>';


gr.addEncodedQuery(encQuery);


3. if it does not work, create a "after" br on the problem table with the code and trigger it from the scheduled job. Just for testing.



harel


View solution in original post

4 REPLIES 4

Harish KM
Kilo Patron
Kilo Patron

replace this


gs.eventQueue("rb.problem.mipm", gr, gs.getUserID(), gs.getUserName());


Regards
Harish

oharel
Kilo Sage

Hi Peter,



Basically, seems fine to me.


Just a thought:


1. change Problem to problem


2. try: var encQuery = '<your query here>';


gr.addEncodedQuery(encQuery);


3. if it does not work, create a "after" br on the problem table with the code and trigger it from the scheduled job. Just for testing.



harel


plowe
Mega Contributor

Thanks - not sure whether it was the case on problem or separating the query but it's creating the log now.


It's case sensitive, so my guess, the first one.



harel