Monday, November 27, 2023

From the join date birth date must be previous at least 18 years.

 

Step 1 : Create a dynamic action on the item P231_BIRTH_DATE

Step 2 :When 

          Event :Change

          Selection Type : Items

          Item :P231_BIRTH_DATE

Step 3:In the true action 

            Action :Execute Javascript code

--------------------------------------------Code:

var birthdayValue = apex.item('P231_BIRTH_DATE').getValue(); // Replace with your birthday item name

var joinDateValue = apex.item('P231_JOIN_DATE').getValue(); // Replace with your join date item name


// Parse date strings with DD/MM/YYYY format

var birthday = parseDate(birthdayValue, 'DD/MM/YYYY');

var joinDate = parseDate(joinDateValue, 'DD/MM/YYYY');


// Calculate 18 years ago from the join date

var eighteenYearsAgo = new Date(joinDate);

eighteenYearsAgo.setFullYear(eighteenYearsAgo.getFullYear() - 18);


if (birthday > eighteenYearsAgo) {

    apex.message.alert("The person must be at least 18 years old at the time of joining.");

    return false; // Prevent form submission

}


return true; // Allow form submission


function parseDate(dateString, format) {

    var parts = dateString.split('/'); // Split by '/'

    var day, month, year;


    if (format === 'DD/MM/YYYY') {

        day = parseInt(parts[0]);

        month = parseInt(parts[1]) - 1; // Months are zero-based in JavaScript

        year = parseInt(parts[2]);

    }


    return new Date(year, month, day);

}


Step 4 : Affected Elements 
            Selection type : items
            items :  P231_BIRTH_DATE

Step 5: 

No comments:

Post a Comment