- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2022 02:59 PM
Hi All,
The below script is working as expected but I need help to modify and remove the weekend from the calculation.
The below advance script is on the calculated tab of field "Aging". The integer type field 'aging' is on scoped application.
(function calculatedFieldValue(current) {
if(current.state == 7){ //7 is closed value of state field on a scoped application
var aging= GlideDateTime.subtract(new GlideDateTime(current.sys_created_on),new GlideDateTime(current.closed_at));
} else {
aging= GlideDateTime.subtract(new GlideDateTime(current.sys_created_on),new GlideDateTime());
}
return aging.getDayPart();
})(current);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 05:47 PM
I'm not sure how you added my code to you instance , I tried and it works well.
See my pics below.
start end and aging
Calculation scripts on field "Aging"
test1
test2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-11-2022 08:12 PM
HI @MR1
Try this.
I have done some tests..but i think needs more tests....
function getdays(dur,startDateTime,endDateTime){
if(startDateTime >= endDateTime){
return dur;
}
if( startDateTime.getDayOfWeekUTC() == 6 || startDateTime.getDayOfWeekUTC() == 7){
var startOfStartDateTime= new GlideDateTime(startDateTime.getDate() + " 00:00:00")
startOfStartDateTime.addDaysUTC(1)
return getdays( dur, startOfStartDateTime ,endDateTime)
}
if(endDateTime.getDayOfWeekUTC() == 6 || endDateTime.getDayOfWeekUTC() == 7){
var nextday = new GlideDateTime(startDateTime.getDate() + " 24:00:00")
nextday.addDaysUTC(-1)
return getdays(dur,startDateTime , nextday)
}
if(startDateTime.getDate() == endDateTime.getDate()){
return dur.add( GlideDateTime.subtract(startDateTime,endDateTime))
}else{
var nextday = new GlideDateTime(startDateTime.getDate() + " 00:00:00")
nextday.addDaysUTC(1)
var endofStartday = new GlideDateTime(startDateTime.getDate() + " 24:00:00")
return getdays(dur.add( GlideDateTime.subtract(startDateTime,endofStartday )),nextday , endDateTime)
}
}
// test !!
var restultdru = getdays(new GlideDuration(0),new GlideDateTime('2022-12-12 24:00:00') , new GlideDateTime('2022-12-13 12:00:01') )
gs.info(restultdru .getDurationValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 06:07 AM
Thanks for your help!
Unfortunately, I tried with that script but it didn't help me out yet.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 06:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 08:27 AM
I was trying to populate a custom integer type field "aging" based on "opened at" and "closed at" fields.
I added your script on the field level advanced script and the result was empty. the field was empty. Do you think any BR could help us as alternative solution.
Thanks