Scheduled Report (Condition)

Dizy M
Tera Expert

Hello all!

I just need your help on this one..

Im making a scheduled report. The condition is It will send the report if there is a "Retired" or "Withdrawn" Account POC on the table. I used Gliderecord to query the table by " Status is one of Active LOA and Active "   AND                                 " AccountPOC.employmentstatus desc is "Retired" or "Withdrawn"...  When I tried it , I wait for the hour that i set on the scheduled report and it seems like the Condition is not working coz it supposed not to send the report since there is no "Retired" Account POC on the table that I query...

 

Please help me with this one 

 

 

find_real_file.png

1 ACCEPTED SOLUTION

Filipe Cruz
Kilo Sage
Kilo Sage

Hi Dizy,

Couple of things you need to change:

1) enclose your code inside a function. Do something like:

executeRule();
function executeRule(){

  //your code here!

}

This is a good practice since this way you guarantee that your code will not be interfered by any other code running with, for example, same variable name.

2) Line 6: you do "if(app == "Retired")
You cannot do this since "app" is a GlideRecord object. You might want to do something like app.field_name == "Retired", where field_name is the name of the field that contain the value "Retired";

3) The code on line 2 seems not to work also. The getValue method needs to be performed against an object. The way you have there is not working;

4) Why are you checking in like 6 for records "Retired"? can't you put that in your condition in the encondedQuery? That might save you some code and some processing time. In that case instead of a while statement you might use simple a 

if(app.next()){
  answer = true;
}
else
  answer = false;

5) If your idea is to validate if your query has data, I recommend using GlideAggregate: https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
This can return you the number of records catched by your condition and you can set answer = true if the result of the GlideAggregate is higher than 0.

Hope my recommendations make sense to you.
Check mainly recommendations 1, 2 and 3 and let me know if that solved your issue.

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

View solution in original post

2 REPLIES 2

Filipe Cruz
Kilo Sage
Kilo Sage

Hi Dizy,

Couple of things you need to change:

1) enclose your code inside a function. Do something like:

executeRule();
function executeRule(){

  //your code here!

}

This is a good practice since this way you guarantee that your code will not be interfered by any other code running with, for example, same variable name.

2) Line 6: you do "if(app == "Retired")
You cannot do this since "app" is a GlideRecord object. You might want to do something like app.field_name == "Retired", where field_name is the name of the field that contain the value "Retired";

3) The code on line 2 seems not to work also. The getValue method needs to be performed against an object. The way you have there is not working;

4) Why are you checking in like 6 for records "Retired"? can't you put that in your condition in the encondedQuery? That might save you some code and some processing time. In that case instead of a while statement you might use simple a 

if(app.next()){
  answer = true;
}
else
  answer = false;

5) If your idea is to validate if your query has data, I recommend using GlideAggregate: https://developer.servicenow.com/blog.do?p=/post/glideaggregate/
This can return you the number of records catched by your condition and you can set answer = true if the result of the GlideAggregate is higher than 0.

Hope my recommendations make sense to you.
Check mainly recommendations 1, 2 and 3 and let me know if that solved your issue.

Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!

Best Regards,

Filipe Cruz

@Filipe Cruz Oh my god Thank you very much for your help! Btw, I tried to use the aggregate and it works fine.