Report that shows all Change Requests that are in Change Approval State before a certain day and time.

Ahmed Nadeem
Kilo Contributor

Our company is changing its Change Management process and they want to deadline to be during the week on Tuesday at 12:00pm. Those changes will be approved by the change manager on Wednesday at 2:00pm at the Change Management Meeting. It needs to be an automated report that shows all Changes Requests in that Approval State that meets the deadline and before.

The issue i am having is creating a report for the meeting that shows all changes that are in Pre-Approval state ready to be approved at the Change Meeting by the Change Admin. When i contacted ServiceNOW, they told me to use the "relative" field and do 26 hours before. The problem with that is if some one gets to Pre-Approval state at 12:15pm, during the meeting on Wednesday at 2:15pm the report will show that change too while the Change Admin is approving the Change and the report reloads. After explaining that to the ServiceNOW Engineer he first told me it can only be done manually. Then later he said i could do it if i write a script for it and run the report that way.

I have no idea what that script would look like and would really appreciate the help. I am fairly new to ServiceNOW and i am still learning.

1 ACCEPTED SOLUTION

I have attached a sample Script Include that is Client Callable, and the sample query that would always fetch the change requests between the last Tuesday after 12PM and this week's Tuesday 12PM.



URL would look like:


http://<instance_name>/change_request_list.do?sysparm_query=sys_created_on%3E%3Djavascript%3Anew%20DayDateTime().getLastWeekEndDateTime(2)%5Esys_created_on%3C%3Djavascript%3Anew DayDateTime().getCurrentWeekStartDateTime(2)



You can modify this query and use it for the reports.


View solution in original post

6 REPLIES 6

Aditya Mallik
ServiceNow Employee
ServiceNow Employee

Can you share your current report. We can help modify it to match the requirement.


Sorry Aditya i probably should have attached it from the beginning. This is the report with out any timings attached to it. Currently, this is the report that the Change Admin runs the Change Meeting with and it shows all the changes requests that are approved and are in CAB Meeting State.


SNC20.PNG


This is what the ServiceNOW Engineer sent me.


--------------------------------------------------------------------------------------------------------------------------------------------------------


Your desired outcome, as I understand it, is to generate a list of records which, aside from other filter options, will include only those records that were created no later than the most recent Tuesday an 12:00 Noon, and no earlier than 12:00 Noon on Tuesday of the previous week. And, as I related during our call, there isn't a way to specify what you would like to do, using the Filter builder UI. You can however craft what's known as a "scripted filter", typically within the framework of a Script Include, which will encapsulate the necessary query / logic using GlideRecord objects. The idea is that the scripted logic will return a list or array of change_request.sys_id values, which you can call with a "Sys ID" filter. For general documentation on doing something like that, for Helsinki, please see Create scripted filters and Use script includes. A couple notes regarding the first link: * The given example of a filter:


[Caller] [is] [javascript:myFunction()]

should instead, for a script include -implemented filter be:


[Caller] [is] [javascript:new NewInclude().myFunction()]

* Your eventually filter used would look more like this:


[Sys ID] [is] [javascript:new CAB_ReportingFunctions().getLastWeekCHGs()]

...for script include "CAB_ReportingFunctions" and filter method getLastWeekCHGs(). * The javascript given looks odd because there are extra spaces added; otherwise, it's syntactically correct. The hardest part of this task will be work up logic to programmatically script a GlideRecord query specific to your date-time requirements, i.e. of setting abstract start- and end-points for that. If you need help there, I would suggest searching the ServiceNow Community, and perhaps posting a new question. (I reminded you that Tech Support can't really assist you with design or implementation tasks; you can however open incidents for API-level questions.) An idea that occurs to me---untested!---is to use the GlideSystem (gs) methods beginningOfThisWeek() and beginningOfLastWeek() as rolling reference points---to which you could add a set number of hours. The Glide APIs are documented at the ServiceNow Developers portal; click the Legacy tab to see classic "global" methods.


-----------------------------------------------------------------------------------------------------------------------------------------------------------


I have attached a sample Script Include that is Client Callable, and the sample query that would always fetch the change requests between the last Tuesday after 12PM and this week's Tuesday 12PM.



URL would look like:


http://<instance_name>/change_request_list.do?sysparm_query=sys_created_on%3E%3Djavascript%3Anew%20DayDateTime().getLastWeekEndDateTime(2)%5Esys_created_on%3C%3Djavascript%3Anew DayDateTime().getCurrentWeekStartDateTime(2)



You can modify this query and use it for the reports.


thanks for the quick responses. I still have a few questions.



1. I would like to have to script run from current Tuesday at 12:00 pm and before (not Tuesday to Tuesday)


2. For me to run the script i would add this in System "Definitions>Script Includes" and then call that form the report?



Thanks again