- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 03:10 AM
I have a catalog item name Leave tracker
I want when user select leave type and leave start and leave end date i want to auto set value on leave balance table after approvel activity in workflow
it should be set in a custom table like in below table
example: i select start leave date tomorrow and end leave date 2 day after start leave date the it should subtract from the table mean if it is standard leave and we have total 3 so it should update taken leave field 2 and leave left 1 using workflow can anybody help me
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 04:12 AM
You can subtract to have the duration between the Leave Start and End date.
Sample below.
var gdtStart = new GlideDateTime(<leave_start_date>); //replace your variable name
var gdtEnd = new GlideDateTime(<leave_end_date>); //replace your variable name
var duration = GlideDateTime.subtract(gdtStart, gdtEnd);
var days = duration.getDayPart();
var gr = new GlideRecord('<your_balance_leave_available>');
gr.query('<caller>', current.variables.requested_for); //replace your field and variable name
gr.query('<leave_type>', current.variables.leave_type); //replace your field and variable name
gr.query();
if(gr.next()){
gr.taken_leave = days; //replace your field name
gr.left_leave = parseInt(gr.balance) - days; //replace your field name
gr.update();
}
You can consider to exclude the weekend for the script.
Sample below.
var schedule = new GlideSchedule();
schedule.load('ded21b2047d27910ab9bb6bf016d43a0'); //24x5 Schedule
var duration = schedule.duration(gdtStart, gdtEnd);
var days = duration.getDayPart();
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 04:12 AM
You can subtract to have the duration between the Leave Start and End date.
Sample below.
var gdtStart = new GlideDateTime(<leave_start_date>); //replace your variable name
var gdtEnd = new GlideDateTime(<leave_end_date>); //replace your variable name
var duration = GlideDateTime.subtract(gdtStart, gdtEnd);
var days = duration.getDayPart();
var gr = new GlideRecord('<your_balance_leave_available>');
gr.query('<caller>', current.variables.requested_for); //replace your field and variable name
gr.query('<leave_type>', current.variables.leave_type); //replace your field and variable name
gr.query();
if(gr.next()){
gr.taken_leave = days; //replace your field name
gr.left_leave = parseInt(gr.balance) - days; //replace your field name
gr.update();
}
You can consider to exclude the weekend for the script.
Sample below.
var schedule = new GlideSchedule();
schedule.load('ded21b2047d27910ab9bb6bf016d43a0'); //24x5 Schedule
var duration = schedule.duration(gdtStart, gdtEnd);
var days = duration.getDayPart();
Let me know if it works for you.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 05:50 AM
ok i will try should i write this code in run script activity in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 07:59 PM
Yes the script can be used inside the workflow. Just make sure to replace the field's name and variable's name.
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-01-2023 09:35 PM
Thanks its working fine