- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 06:34 AM
Hi All, I'm looking for a way to create a more simple report showing incidents over time.
The report I want to make requires me to be able to create a pivot table or bar chart where I can group by month and year
The report will conditions will be as follows.
Table = Incident
Column - Custom field "u_month"
Row - Club Name
Created ON Last 12 months
Coul anyone help me with a script to put on the business rule on insert?
I've attached a screen shot of the hopeful result.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 07:06 AM
Hi Carl,
here is your script which you can add to business rule and accordingly populate the month and year values in whichever field you want:
var nowDateTime = new GlideDateTime(current.sys_created_on);
var date = nowDateTime.getDate();
var month = date.toString().split("-")[1];
var year = date.toString().split("-")[0];
current.u_month = month;
current.u_year = year;
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 06:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 07:06 AM
Hi Carl,
here is your script which you can add to business rule and accordingly populate the month and year values in whichever field you want:
var nowDateTime = new GlideDateTime(current.sys_created_on);
var date = nowDateTime.getDate();
var month = date.toString().split("-")[1];
var year = date.toString().split("-")[0];
current.u_month = month;
current.u_year = year;
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 07:12 AM
Thank you for your reply.
In looking at this…if I read it correctly, we're getting the month and year in to separate fields…
I'm trying to think how the report will look.
I think I need the put both in a single field or will be confused when grouping by month as to which year it is when doing the "last 12 months".
So an incident created today would get the value of "Jun.17" or "June 2017" then when I group by the single columns "u_mth_yr_string" it will be clearly sorted.
Is that possible? Sorry I should have clarified but thank you again!.
Regards,
Carl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2017 07:48 AM
Carl,
It's JavaScript, so if you don't want them in separate fields, you can just concatenate the strings together into a third field:
current.u_month = month;
current.u_year = year;
current.u_reportdate = month+"."+date
Hope that helps.
-Rob