One of our most frequent uses of cfl_ch_2-the_cfl_language is in creating layout reports for the printing of Estimates, Work Orders, and Invoices. Our delivery product began with just a few checkboxes but as we grew and the number of ways we deliver changed, we added more and more check boxes - E.g. UPS, then UPS Next Day, Then UPS 2 Day, Then UPS 3 Day, etc. The original code began to become unwieldy with multiple if statements; so we switched to the Case Statemen with Declared Variables. Now it takes only a couple of mintues to add a variable and a message to the layout report.

We reduced the amount and complexity of the code to produce various “messages” or text lines depending on which checkbox is selected in the pricing form.

When working with locally delcared variables, it appears to us (not confirmed by Cyrious) the the way the code is compiled it is possible to have a conflict if you have a local variable with the same name in different variables within the same product. To avoid that problem we use a unique two-letter differentiator depending on where the declaration is made. For eample, if we are using it the Product Pricing Code, we precende the variable with a “PR”. For example, in declaring a local variable “JobDelivers” we would declare it as PR_JobDelivers as in Declare PR_JobDelivers; Then, if someone uses that same name in a variable DeliveryPricing, they would declare it as DP_JobDelivers. There are probably more elegant solutions others can suggest but this works. (Note that the code below was written before we began this convention.)

  1. In the layout we set up a variable to return a numeric code for each of the checkbox variables. Creating a variable with any name you want is as easy as typing Declare and your variable name, all one word. You follow it with a semi-colon and it's done. If you want to give it a value you follow it with the colon-equal sign - E.g. :=. If you want to give it a string value, you must enclose that in quoation marks. If its a number, just enter the number. If you want it to be a Yes/No then set it equal to TRUE or FALSE. You end the line with a semi-colon. The Cyrious Cyurious Formula Language Guide has more information and examples about its code and how to use it.
  2. We then create a Case Statement which determines the message to be printed depending on which of the variables is selected on the pricing form. Note here that some of the Checkboxes are Modifers and their value is returned with the DisplayModifierValue() function. With Yes/No Varaibles you don't even need the full IF THEN syntax, as you see below. You can skip the IF commercialshipper = True then “…….” and simply say “If CommercialShipper” THEN ……………
Declare IsUPS :=
       IF DisplayModifierValue("UPS") = "YES" THEN 2 ELSE
       IF DisplayModifierValue("Overnight-Rush") = "Yes" THEN 3 ELSE
       IF DisplayModifierValue("StandardUPS") ="YES" THEN 1 ELSE
       IF commercialshipper Then 6 ELSE
       If  DisplayModifierValue("Deliver") ="Yes" THEN 7 ELSE
       IF GivetoSalesperson Then 8 ELSE
       IF DisplayModifierValue("UPS3DayAir") = "Yes" THEN 9
       ELSE 0
       ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ;
Declare ShipMethod := IF ISUPS > 0 THEN
                      Case ISUPS is 1 THEN "Ship UPS Ground: "
                                                2 Then "Ship UPS Next Day Air "
                                                3 Then "Ship UPS 2 Day Air"
                                                5 then "Send By US Mail: "
                                                6 then "Ship Commercial Carrier "
                                                7 then  "Deliver To: "
                                                8 then "Give To  " + TransHeader.SalesPerson1.FirstName + " "+ TransHeader.SalesPerson1.LastName + " for Delivery"
                                                9 Then "UPS 3 Day Air"
                     ENDCASE
  else "" endif;

3. The Code to generate your message on the Estimate, Work Order or Invoice you simple include ShipMethod at the conclusion of your Declaration statements. Note in the code above we used the Property which returns the Primary Salesperson's name to make the Screen presentation printouts a little more user friendly. The code would return the message without the addition of the final line, but we go the extra step to make sure we dont get confused about what is doing what. THe sem-colon is not necessary in the last line.

Declare IsUPS :=
       IF DisplayModifierValue("UPS") = "YES" THEN 2 ELSE
       IF DisplayModifierValue("Overnight-Rush") = "Yes" THEN 3 ELSE
       IF DisplayModifierValue("StandardUPS") ="YES" THEN 1 ELSE
       IF commercialshipper Then 6 ELSE
       If  DisplayModifierValue("Deliver") ="Yes" THEN 7 ELSE
       IF GivetoSalesperson Then 8 ELSE
       IF DisplayModifierValue("UPS3DayAir") = "Yes" THEN 9
       ELSE 0
       ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ;
Declare ShipMethod := IF ISUPS > 0 THEN
                      Case ISUPS is 1 THEN "Ship UPS Ground: "
                                                2 Then "Ship UPS Next Day Air "
                                                3 Then "Ship UPS 2 Day Air"
                                                5 then "Send By US Mail: "
                                                6 then "Ship Commercial Carrier "
                                                7 then  "Deliver To: "
                                                8 then "Give To  " + TransHeader.SalesPerson1.FirstName + " "+ TransHeader.SalesPerson1.LastName + " for Delivery"
                                                9 Then "UPS 3 Day Air"
                     ENDCASE
  else "" endif;
 ShipMethod

Contributor: Steve Gillispie, Acorn Sign Graphics

Date: _07/16_/2009

Version: Control 4.3_

You could leave a comment if you were logged in.