Expand my Community achievements bar.

SOLVED

JavaScript coding of three tier discount levels

Avatar

Level 4

Hello,

I have scripted for a three tiered discount order form, which, works with the following code:

if (xfa.resolveNode("subTotal.numTotalUnits").rawValue < xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subBelow.numUnitBelow").rawValue;

}

else if (xfa.resolveNode("subTotal.numTotalUnits").rawValue >= xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1").rawValue && xfa.resolveNode("subTotal.numTotalUnits").rawValue < xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount1").rawValue;

}

else if (xfa.resolveNode("subTotal.numTotalUnits").rawValue >= xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2").rawValue && xfa.resolveNode("subTotal.numTotalUnits").rawValue < xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount2").rawValue;

}

else if (xfa.resolveNode("subTotal.numTotalUnits").rawValue >= xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount3").rawValue;

}

However, the issue is that while the code above works, it only works when there are three discount levels and at that time calculates appropriately.

The three discount levels would not apply to all items ordered, therefore; I need a method to only calculate if the subsequent discount level is entered in the field.

I have tried null verification checks, however, I am not able to get it working. The null verification check should only be on the subsequent discount level, and, if present the next level needs to be checked prior to attempting a verification of the TotalUnits.

Any help would, of course, be very welcome.

Thank you in advance,

Lewis

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Lewis,

Sounds like you do need a null test, maybe something like;

var numTotalUnits = xfa.resolveNode("subTotal.numTotalUnits");

var numThreshold1 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1");

var numThreshold2 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2");

var numThreshold3 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3");

if (numTotalUnits.rawValue < numThreshold1.rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subBelow.numRegularPrice").rawValue;

}

else if (!numThreshold2.isNull && (numTotalUnits.rawValue >= numThreshold1.rawValue && numTotalUnits.rawValue < numThreshold2.rawValue)){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount1").rawValue;

}

else if (!numThreshold2.isNull && !numThreshold3.isNull && (numTotalUnits.rawValue >= numThreshold2.rawValue && numTotalUnits.rawValue < numThreshold3.rawValue)){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount2").rawValue;

}

else if (!numThreshold3.isNull && (numTotalUnits.rawValue >= numThreshold3.rawValue)){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount3").rawValue;

}

Regards

Bruce

View solution in original post

4 Replies

Avatar

Level 4

I have modified slightly the code with a name change to a field in order to better display the requirement:

if (xfa.resolveNode("subTotal.numTotalUnits").rawValue < xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subBelow.numRegularPrice").rawValue;

}

else if (xfa.resolveNode("subTotal.numTotalUnits").rawValue >= xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1").rawValue && xfa.resolveNode("subTotal.numTotalUnits").rawValue < xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount1").rawValue;

}

else if (xfa.resolveNode("subTotal.numTotalUnits").rawValue >= xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2").rawValue && xfa.resolveNode("subTotal.numTotalUnits").rawValue < xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount2").rawValue;

}

else if (xfa.resolveNode("subTotal.numTotalUnits").rawValue >= xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3").rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount3").rawValue;

}

You will notice within the first "if" statement the value is now set to "numRegularPrice".

Any help would be well received.

Thank you,

Lewis

Avatar

Correct answer by
Level 10

Hi Lewis,

Sounds like you do need a null test, maybe something like;

var numTotalUnits = xfa.resolveNode("subTotal.numTotalUnits");

var numThreshold1 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1");

var numThreshold2 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2");

var numThreshold3 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3");

if (numTotalUnits.rawValue < numThreshold1.rawValue){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subBelow.numRegularPrice").rawValue;

}

else if (!numThreshold2.isNull && (numTotalUnits.rawValue >= numThreshold1.rawValue && numTotalUnits.rawValue < numThreshold2.rawValue)){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount1").rawValue;

}

else if (!numThreshold2.isNull && !numThreshold3.isNull && (numTotalUnits.rawValue >= numThreshold2.rawValue && numTotalUnits.rawValue < numThreshold3.rawValue)){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount2").rawValue;

}

else if (!numThreshold3.isNull && (numTotalUnits.rawValue >= numThreshold3.rawValue)){

this.rawValue = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount3").rawValue;

}

Regards

Bruce

Avatar

Level 4

Worked like a charm.

Thank you,

Lewis

Avatar

Level 4

Spoke too soon, had to make amendments to the code, need it to trigger based on the three tiers, have this so far:

var numTotalUnits = xfa.resolveNode("subTotal.numTotalUnits");

var numThreshold1 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold1");

var numThreshold2 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold2");

var numThreshold3 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numThreshold3");

var numRegularPrice = xfa.resolveNode("this.parent.parent.parent.subControls.subBelow.numRegularPrice");

var numDiscount1 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount1");

var numDiscount2 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount2");

var numDiscount3 = xfa.resolveNode("this.parent.parent.parent.subControls.subVolume.numDiscount3");

if (numThreshold1.rawValue == null || numThreshold1.rawValue == ""){

this.rawValue = numRegularPrice.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue == null || numThreshold2.rawValue == "" && numDiscount2.rawValue == null || numDiscount2.rawValue == "" && (numTotalUnits.rawValue < numThreshold1.rawValue)){

this.rawValue = numRegularPrice.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue == null || numThreshold2.rawValue == "" && numDiscount2.rawValue == null || numDiscount2.rawValue == "" && (numTotalUnits.rawValue >= numThreshold1.rawValue)){

this.rawValue = numDiscount1.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && numThreshold3.rawValue == null || numThreshold3.rawValue == "" && numDiscount3.rawValue == null || numDiscount3.rawValue == "" && (numTotalUnits.rawValue >= numThreshold1.rawValue && numTotalUnits.rawValue < numThreshold2.rawValue)){

this.rawVaue = numDiscount1.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && numThreshold3.rawValue == null || numThreshold3.rawValue == "" && numDiscount3.rawValue == null || numDiscount3.rawValue == "" && (numTotalUnits.rawValue >= numThreshold2.rawValue)){

this.rawValue = numDiscount2.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && numThreshold3.rawValue != null && numDiscount3.rawValue != null && (numTotalUnits.rawValue >= numThreshold2.rawValue && numTotalUnits.rawValue < numThreshold3.rawValue)){

this.rawValue = numDiscount2.rawValue;

}

else if (numThreshold1.rawValue != null && numDiscount1.rawValue != null && numThreshold2.rawValue != null && numDiscount2.rawValue != null && numThreshold3.rawValue != null && numDiscount3.rawValue != null && (numTotalUnits.rawValue >= numThreshold3.rawValue)){

this.rawValue = numDiscount3.rawValue;

}

So, in the above I need it to trigger after verifying each trigger level and as the discounts change.

The above seems to work well when all three are populated, but, does not work completely as expected for when the discounts are of only 2 levels or 1 level.

Any additional assistance is greatly appreciated.

Lewis