- 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-12-2022 09:02 AM
I tried with this script. it was working in the background script but not via business rule
var start = new GlideDateTime('2022-12-12 17:38:25');
var end = new GlideDateTime('2022-12-12 16:38:25');
var u_age = getDateDiffExcWeekends(start, end);
gs.info(u_age);
function getDateDiffExcWeekends(start , end){
var u_age = 0;
while (start < end) {
start.addDaysUTC(1);
if (start.getDayOfWeekUTC() != 6 && start.getDayOfWeekUTC() != 7){
u_age++ ;
}
}
return u_age;
}
gs.info('test age');
- 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-12-2022 07:53 PM
I appreciate your response!
But the script you shared earlier and the script in the attached screenshot looks different.
Let me try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 08:04 PM
The script i posted earlier is the core part...(a function to calculate the duration.. )
You need to call the function in your scripts( like the newest post)...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2022 08:09 PM - edited 12-12-2022 08:22 PM
Thanks a lot!
It worked
Could you please help me to remove the holidays also?