- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 03:52 AM
Dears,
I need to get records (CIs) with Installed date in the current month, regardless of the year.
In ServiceNow there are already some 'trend' filter to do this, but only a static month can be used:
How can I implement the same filter, but with the condition 'Installed trend on current month'?
Thank you,
Sutot
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 05:16 AM
hi,
I got your issue you are looking for records installed on a current month regardless of the year.
So one thing that you can do is to create a script include and set the filter to sys_id isOneOf javascript:getTrendONCurrentMonth('field_name','table_name')
here is how you can use that script include in filter
script include should be client callable
here is the code for script include
this code will automatically get the current month and will return the trend on records.
function getTrendONCurrentMonth (fieldName,tableName) {
var StringMonth='';
var shortMonth='';
var integerMonth=new GlideDateTime().getMonth();
switch(integerMonth)
{
case 1:
StringMonth='January';
shortMonth='jan';
break;
case 2:
StringMonth='February';
shortMonth='feb';
break;
case 3:
StringMonth='March';
shortMonth='mar';
break;
case 4:
StringMonth='April';
shortMonth='apr';
break;
case 5:
StringMonth='May';
shortMonth='may';
break;
case 6:
StringMonth='June';
shortMonth='june';
break;
case 7:
StringMonth='July';
shortMonth='july';
break;
case 8:
StringMonth='August';
shortMonth='aug';
break;
case 9:
StringMonth='September';
shortMonth='sep';
break;
case 10:
StringMonth='October';
shortMonth='oct';
break;
case 11:
StringMonth='November';
shortMonth='noc';
break;
case 12:
StringMonth='December';
shortMonth='dec';
break;
}
var sys_ids='';
var g=new GlideRecord(tableName);
g.addEncodedQuery(fieldName+"DATEPART"+StringMonth+"@javascript:gs.datePart('month','"+shortMonth+"','EE')");
g.query();
while(g.next())
{
if(sys_ids=='')
{
sys_ids+=g.getUniqueValue();
}else{
sys_ids+=','+g.getUniqueValue();
}
}
return sys_ids.toString();
}
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Hammad ul Aziz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 04:05 AM
Hi,
Instead of trend, why don't you use on operator and select "This month"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 04:24 AM
Dear asifnoor,
thank you for your answer.
'This month' condition is for the current month of the current year (e.g: July 2020). What I need is to get records with Installed date in this month, regardless of the year (e.g: July 2020, July 2019, July 2018, ... July 2015, ...)
Sutot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 04:59 AM
Aha. So you want records created in the month of July of any year?
If thats the case, then select
Trend on July and run.
Then it will filter all records of the month of july of any year.
Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.
Regards,
Asif
2020 ServiceNow Community MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2020 04:08 AM
Hi,
what if you give installed on this month filter?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
