Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Date Calculation on Report

msm4
Mega Guru

HI Team,

I have requirement, where I need to set a filter to check for a specific day from laskweek. 

Example: I need to fetch records where the "week_starts_on" that specific day.

I have written the logic in a script Include and want to call that in report filter using "javascript: " , but I am not sure if it is possible.

Could you please suggest me how this can be achieved. Below is the screenshot where I want to call the script Include

Thanks.

 

9 REPLIES 9

Community Alums
Not applicable

Hello,

The attached screen shot is broken, could you please attach it again.

 

Hello Akshay,

Thanks for the response, Please find the below:

I am not getting where I can call the script Include here, the list of operators for the date field will not allow me to call the script Include. how do I get my calculated date for the filter here?

Please advise.  

find_real_file.png

Community Alums
Not applicable

Hello,

Could you please share script include code. If you are finding some records based on conditions you can return sys_id.

Suppose, if your condition is "created on last week" then it will show records created on last week.

Similarly you can apply this logic in script include and return sys_id of records in array and call this in filter condition "Sys id is one of script_include_name".

 

Regards,

Akshay

Community Alums
Not applicable

Hello,

Try below code in your script include -

in your report use this filter:

sys_id || Isoneof || javascript: new scriptincludename().functionname()

 var gd = new GlideDate().getDate();
 var lastWeek = gd.getDayOfWeek() + 9;
 gw = new GlideDateTime(gd);
 gw.addDays(-(lastWeek));

 var arr = [];
 var gr = new GlideRecord('your_table_name');
 gr.addQuery("time_card.week_starts_on", "STARTSWITH", gw);
 gr.query();
 while (gr.next()) {

     arr.push(gr.sys_id.toString());
 }
return arr;

 

Please check and let me know if you have any queries.

 

Regards,

Akshay