Examples for Employment Processes
This topic lists some examples of javascript code that you can use for use cases in employment processes.
Looping through Assignment History
function runCondition(context) {
const { $componentContext, $fields, $modules, $user, $value } = context;
const empWorkerAsgHistory = $fields["employmentWorkerAssignmentHistory"].$value();
if(empWorkerAsgHistory){
const empAsgHistory = $fields["employmentWorkerAssignmentHistory.employmentAssignmentsHistory"].$value();
if(empAsgHistory) {
for(const key in empAsgHistory) {
if(empAsgHistory[key].ActionCode === "ASG_CHANGE"){
return true;
}
}
}
}
return false;
}
return { runCondition };
});
When When and Why date is on a 1st or 15th of a month
function isFirstOrFifteenth(date) {
const day = date.getDate();
if (day === 1 || day === 15) {
return true; // The date is on the 1st or 15th
}
return false; // The date is not on the 1st or 15th
}
Get the difference in years between two date
objects
//d1 and d2 are date objects and d2 > d1
function dateDiff(d1,d2) {
let diff = (d2.getTime() - d1.getTime()) / 1000;
diff /= (60 * 60 * 24);
return (diff / 365.25);
}
Subtract or add months from given date
function subtractMonthsFromDate(inputDate, months) {
const date = new Date(inputDate);
date.setMonth(date.getMonth() - months);
return date;
}
Function to check if the current year is a leap year
//date is a Date object
function isLeapYear(date) {
const year = date.getFullYear();
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
return true;
}
return false; // The year is not a leap year
}