For this project we need to add a line item, that is essentially a 3% fee for Credit Card processing, to a Marketing Document. The instructions would be the same for adding basically any line item, and calculating its attributes.
First things first, we’ll add the Function Button to our form. In this case, a Sales Order (Form Type 139).
This button, when pressed, kicks off UF-038. (Getting very creative with my naming conventions.) UF-038 is a Macro.
@STORE1 = $[$29.0.NUMBER] @STORE2 = 0.03 @STORE3 = @STORE1*@STORE2 Set($[$38.1.0.LAST]|CCFEE); Set($[$38.14.CURRENCY.FOCUSED]|@STORE3);
I can’t explain exactly what’s going on here, but it has something to do with the way that B1UP does math in macros, and the way that it sees strings vs numbers.
All we’re doing here is setting @STORE1 to the value of the document’s TOTAL, which is item “29” on this form.
Then we’ll set @STORE2 to 0.03, as we’re trying to add a fee that is 3% of the total.
And finally, set @STORE3 to be the [Total Amount] * 0.03
The next part had me stuck for a minute, but it actually makes perfect sense. Since we don’t know how many lines will be on each document, B1UP makes it easy to find the last line with “.LAST”
Our Set($[$38.1.0.LAST]|CCFEE);
command goes to the LAST line in Item 38 (the line item detail pane), column 1 (the Item Number column) and enters the item number “CCFEE”.
The next line, Set($[$38.14.CURRENCY.FOCUSED]|@STORE3);
doesn’t set the LAST line (because that would be the line BELOW our CCFEE), it sets the price column on the line with FOCUS, which is the line that we just inserted the “CCFEE” into.
That’s basically it. But this has a ton of use-cases.
Of course, this doesn’t control for if a user has already added the CCFEE, so in theory clicking this button multiple times would add multiple CCFEE’s. We need to trap for that possibility, and figure out other ways that our users can break this (because believe me, they will.)