Script rule related doubt


i calculated the drivers age using script rule but in DriversAge the value is null then it always getting rejected ,in decision table i checked if DriversAge is between 18 or 80 then approve otherwise reject but it always getting rejected after testing,so i think the value is not entered in DriversAge .how i fixt this ? ,after this i can go to the next main checks

1 Like

@sam @Rocky @sajjad.rehman Please help

Created a script rule for finding the drivers age and in decision table iam always checking if age is valid or not ,but i think the actual value is entered inside drivers age after calculation how i fix this

1 Like

Hi @navaneethck_10, When you pass the string IP_DriverDOB (in dd/mm/yyyy format) directly to new Date(), JavaScript’s Date constructor does NOT reliably parse this format. It may interpret the date incorrectly as mm/dd/yyyy or return Invalid Date. This causes driversYear to be incorrect or NaN, so the age calculation fails.

To fix this, you should manually split the date string and construct the Date object like this:

const [day, month, year] = IP_DriverDOB.split(‘/’);
const driversDOB = new Date(year, month - 1, day);
const currentYear = new Date().getFullYear();
OP_driverAge = currentYear - driversDOB.getFullYear();