Skip to main content
Known Participant
December 27, 2019
Answered

Need a script to complete this form...

  • December 27, 2019
  • 3 replies
  • 974 views

Is there an existing script that will auto-calculate "B" and "C" when keying in a number value for "A", based on "D" OR "E"? (see attached) Any help would be greatly appreciated. Thanks in advance.

This topic has been closed for replies.
Correct answer try67

Multiply the result by the item price.

3 replies

try67
Community Expert
Community Expert
December 31, 2019

You can use this code as the custom calculation script of the "Free Qty" field:

 

var totalItems = Number(this.getField("Qty").valueAsString);
var freeItems = Math.floor(totalItems/100);
totalItems -= freeItems*100;
freeItems += Math.floor(totalItems/11);
event.value = freeItems;
Known Participant
December 31, 2019

That's awesome, thank you. But how do i get the subtotal to calculate based on the quantity selected with the 3 different price points?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
January 1, 2020

Multiply the result by the item price.

try67
Community Expert
Community Expert
December 27, 2019

This is certainly possible, but you need to better explain how it should work.

Is the number in A free for you the user to enter? What should happen if they enter 54, for example?

Known Participant
December 31, 2019

Thanks for the response try67. If it’s possible to populate the FREE field that would be great, but I don’t believe it’s necessary.  My understanding for the BUY 11, Get 1 Free and BUY 100, GET 20 Free is that partial orders do not receive FREE QTY.   If they enter 54 for the Buy 11 Get 1 FREE it would be 4 Free since they would have to purchase 55 to obtain 5 FREE.  The Net GSP price/unit remains the same.

 

11-21, get 1 free

22-32, get 2 free

33-43, get 3 free … and so on.

Legend
December 27, 2019

A script could certainly be written. You won't find that scripts just exist already, there are countless trillions of possible needs. Many of us see our task here as helping to learn to write your own scripts. Do you have any coding experience already?