Need to restrict Fiscal periods on the demand cost plans based on the selected date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2024 09:41 PM - edited 08-26-2024 09:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-27-2024 10:39 PM
Hi @Sanjeeva Nagend ,
_freeze_date is this an OOB field or custom field on the cost plan ?
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 12:07 AM - edited 08-28-2024 12:08 AM
Hi @Sanjeeva Nagend ,
I have create a custom field in my instance u_freeze_date.
If the freeze date is not filled, then it will compare start date time of the fiscal period
If the freeze date is filled, then it will compare the start date time and the Freeze date of the fiscal period.
var grFiscalPeriod = new GlideRecord('fiscal_period');
//grFiscalPeriod.addQuery('sys_id', '');
grFiscalPeriod.query();
var array = [];
while (grFiscalPeriod.next()) {
var startTime = new GlideScheduleDateTime();
startTime.setValue(grFiscalPeriod.start_date_time);
var today = new GlideDateTime();
var compareStartDate = startTime >= today;
/****
* If Freeze date is not present
****/
if (grFiscalPeriod.u_freeze_date.isNil()) {
//gs.info('In first IF');
/******
* Compare Start date
********/
if (compareStartDate) {
//gs.info('In second IF');
array.push(grFiscalPeriod.name.toString());
}
} else {
//gs.info('In Fist Else');
var todayFreeze = new GlideDate();
var compareFreezeDate = grFiscalPeriod.u_freeze_date >= todayFreeze;
// gs.info('Today ' + todayFreeze);
// gs.info('Freeze date:' + grFiscalPeriod.u_freeze_date);
// gs.info(compareFreezeDate);
/******
* Compare Start date and Freeze Date
********/
if (compareStartDate && compareFreezeDate) {
//gs.info('IN if of ELSE');
//count++;
//array.push(grFiscalPeriod.sys_id.toString());
array.push(grFiscalPeriod.name.toString());
}
}
}
gs.info(array);
gs.info(array.length);
Run this script in the scripts - background, by taking one particular record sys_id in the second line of code to validate your requirement.
Hope this information helps you.
Kindly mark it as Helpful, if this information helps and Accept the solution.
Regards,
Najmuddin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-28-2024 10:09 PM
Hi Nizamuddin,
Thanks for your reply.
I have tried your script, for every fiscal period date was tomorrows date. But current month is not visible.