Hi all,
I have an adobe form which has a fair bit of javascript coding behind it. Basically based on how various fields in the form are answered it will determine an Ultimate Approver calculation.
What we are trying to do?
From the existing code below, we need to add a conditional logic whereby if there is a change to both Date (changeInContractDuration) and Value (changeInSpend) , the Ultimate Approval should = changeInSpendTier.
The code is below. Section D is what we’ve just created to try and get this result but it is not working so something must be logically wrong.
I’m hoping someone can read this script and simply advise what is wrong with Section D coding or the logic behind the coding to get this result.
Really appreciate any feedback.
* Determines the ultimate approver for amendment agreement types
*/
function calculateUltimateApproverForAmendment() {
var result = "";
var isPSDDRequired = true;
var changeInContractDuration = parseInt(PSDD.formExecutiveSummary.subformAmendment.tfContractDurationChange.rawValue);
var changeInSpend = parseFloat(PSDD.formExecutiveSummary.subformAmendment.tfChangeInSpend.rawValue);
var changeInSpendTier = getApproverTier(changeInSpend);
var highestApproverToDateIndex = PSDD.formExecutiveSummary.subformAmendment.ddHighestApproverToDate.selectedIndex;
var newCumulativeValueTier = getApproverTier(parseFloat(PSDD.formExecutiveSummary.subformAmendment.tfCumulativeValueNew.rawValue));
if(isContactCentreBackOfHouseProject()) {
// A. If Contact Centre Back of Hose is checked, use that approval flow.
result = jsData.APPROVERS_CC[jsData.APPROVERS_CC.length - 1];
} else if(PSDD.formExecutiveSummary.subformAmendment.ddMaterialChangeContract.rawValue == 1 && changeInSpend == 0) {
// B. If material change is yes and change in spend and == 0, UltApprover is from 0-2 tier.
result = jsData.ULTIMATE_APPROVERS[0];
} else if(PSDD.formExecutiveSummary.ddCOGSDVC.rawValue == 1 && PSDD.formExecutiveSummary.ddAgreementType.rawValue == 2) {
// C. If COGS == yes, is an amendment form, and no change in contract duration, UltApprover is "No PSDD required".
if(changeInContractDuration == 0) {
result = "No PSDD required";
isPSDDRequired = false;
} else {
result = jsData.ULTIMATE_APPROVERS[0];
}
} else {
// D. Else, Check that the date and value field is changing
if (changeInContractDuration == 1) {
isPSDDRequired = true;
// If the contract date and value is changing, use the change in spend.
result = jsData.ULTIMATE_APPROVERS[changeInSpendTier];
} else {
// If Date is not changing, use the new cumulative value.
result = jsData.ULTIMATE_APPROVERS[newCumulativeValueTier];
}
// E. Else, Compare the highest approver to date and new cumulative value fields.
if(highestApproverToDateIndex >= newCumulativeValueTier && highestApproverToDateIndex != 8) {
// If the contract is staying in the same tier, or was approved in a higher tier, use the change in spend.
result = jsData.ULTIMATE_APPROVERS[changeInSpendTier];
} else {
// Highest approver tier is less than the new cumulative value tier, use the new cumulative value.
result = jsData.ULTIMATE_APPROVERS[newCumulativeValueTier];
}