Hi All,
Using below method calling on save form & on change of prod sub type & dob change too.
/// Calculate age based on DOB & pop up error if age is not between min & max age value from Product Config
Deal_Retail.calculateAgeBasedOnDOB = async function(executionContext) {
"use strict";
try {
if (executionContext !== null && executionContext !== undefined) {
var eventArgs = executionContext.getEventArgs();
if (FormContext !== undefined && FormContext !== null) {
var productId = null;
var customerType = FormContext.getAttribute(attributes.CUSTOMER_TYPE); //New or existing
var customerTypeVal = null;
if (customerType !== null && customerType !== undefined) {
customerTypeVal = customerType.getValue();
}
var subproductAttribute = FormContext.getAttribute(attributes.PRODUCTSUBTYPE);
var productAttribute = FormContext.getAttribute(attributes.PRODUCT_TYPE);
if (subproductAttribute !== undefined && subproductAttribute !== null) {
var subProductValue = subproductAttribute.getValue();
if (subProductValue !== undefined && subProductValue !== null) {
productId = subProductValue[0].id.replace(/[{}]/g, "");
} else {
if (productAttribute !== undefined && productAttribute !== null) {
var productValue = productAttribute.getValue();
if (productValue !== undefined && productValue !== null) {
productId = productValue[0].id.replace(/[{}]/g, "");
}
}
}
}
if (productId !== null) {
var dobFormContext = FormContext.getAttribute(attributes.DOB);
if (dobFormContext !== undefined && dobFormContext !== null) {
var dobValue = dobFormContext.getValue();
if (dobValue !== null && dobValue !== undefined) {
var val = Deal_Retail.GetAge((dobValue.getMonth() + 1), dobValue.getDate(), dobValue.getFullYear());
var ageYear = val.years;
var agemonth = val.months;
var ageday = val.days;
var productConfigRecordsMin = await Deal_Retail.GetProductConfigRecords(ProductConfiguration.MinimumAgeForAnnuityPensionPlan, productId);
var productConfigRecordsMax = await Deal_Retail.GetProductConfigRecords(ProductConfiguration.MaximumAgeForAnnuityPensionPlan, productId);
if (productConfigRecordsMin !== undefined && productConfigRecordsMin !== null && productConfigRecordsMax !== undefined && productConfigRecordsMax !== null) {
var minValue = parseInt(productConfigRecordsMin.entities[0].new_value);
var maxValue = parseInt(productConfigRecordsMax.entities[0].new_value);
var isEligible = (minValue !== null && ageYear >= minValue) && (maxValue !== null && ageYear <= maxValue);
var isRestrict = (ageYear === maxValue) && (agemonth > 0 || ageday > 0);
if (!isEligible || isRestrict) {
var message1 = new RegExp(common_Retail.getResourceString(resx.PROSPECT_RETAIL_FORM, "AlertDOB")).toString();
if (customerTypeVal !== null && customerTypeVal !== undefined) {
if (customerTypeVal !== 100080001) {
common_Retail.openAlertDialog("Ok", message1.substr(1, message1.length - 2));
var productConfigRecordsDOB = await Deal_Retail.GetProductConfigRecords(ProductConfiguration.DOBMandatoryAgePCFVisible, productId);
if (productConfigRecordsDOB !== undefined && productConfigRecordsDOB !== null) {
var dobMandatoryValue = productConfigRecordsDOB.entities[0].new_value;
if (dobMandatoryValue !== null && dobMandatoryValue === "Yes") {
dobFormContext.setValue(null);
}
}
} else {
common_Retail.openAlertDialog("Ok", message1.substr(1, message1.length - 2));
if (eventArgs !== null && eventArgs !== undefined) {
eventArgs.preventDefault();
}
}
}
}
}
}
}
}
}
}
} catch (e) {
common_Retail.openAlertDialog("Ok", e.message);
}
};
Anything doing wrong above functionality is working & throwing alert but after alert its saving the record which it should not save the page anything any idea?
Thanks,
Jharana