Occasionally, you will need to assure that certain variables are selected before a Pricing Form is saved or that the wrong combination of variables have not been selected, etc. Cyrious provides a powerful tool in the pricing_ch_03-products portion of the Product Pricing page to accomplish this. We can create code which examines each of the required variables and if a value is not found in one or is found in too many, we can notify the user of the error and force him to correct it before it is possible to save the product pricing form. The code for this requires that Cyrious look at each variable, determine if it is checked (for this example all variable are check boxes) and if more than one is checked. Since thecfl_ch_2-the_cfl_languageIf Statement or cfl_ch_2-the_cfl_language will terminate the first time the condition is met – ie they find a variable which has been checked, it is pretty cumbersome to write code for this with these functions. We used a simple Loop for this purpose to be sure that each of the variables in this list is evaluated. Thecfl_ch_3-formulas_and_functions provides this code in the “cfl_ch_2-the_cfl_language” selection list. We then used a “counter” which adds up the number of times Cyrious finds a checked variable, If it finds none are checked, we can return an error message directing the user to make a selection. If it finds more than 1 are checked, we direct the user to make only one selection..

The concept is to create a counter which will count the number of “loops” and cause cfl_ch_2-the_cfl_language to evaluate each variable in a list of variables. For our Delivery product we have check boxes for different possible types of delivery, each producing a different price. Checking one of these check boxes creates a price.

After implementation we found 2 problems with this approach. First, we noticed that some users were checking some portions of the form but forgetting to select any type of delivery, closing the form without creating a shipping or delivery price. Or, some users were checking more than one delivery method creating too high a price or a confusing Work order. So we needed to create code which would stop the save if no selection had been made with the correct error message or to stop the save and request that the user select only one method if more than one selection was made.

The code below when combined with the how_to_use_declare_and_case_statements_to_simplify_layouts causes CFL to evaluate each of the cfl_ch_2-the_cfl_language variables (checkboxes) in the list. If it finds one that is checked, it increments the counter by 1. When the loop is complete, the counter will contain the number of variables which have been checked, We then use a simple IF..THEN“ Statement to select the appropriate error message when the form is saved. Below is a screen shot of the actual pricing form for which we are creating the error trap.

There is not much to worry about with this code other than to be sure that it is set so that all variables are being tested and also that the loop will end when complete.

  1. Locate and Edit the Product for which the error trap is desired. Next Open the Product Error CFL formula editor.
  2. Create acfl_ch_5-variables which will be the “counter” or number of times the loop has iterated. Ex: Declare Counter := 0;
  3. Create a variable to count the number of selections which have been made. (Remember that we want to limit the User to only one selection! Example: Declare NumberofCheckedVariableSelected := 0;
  4. Create a variable to count the number of iterations in the loop. Example: Declare VariableCounter := 0; When creating or declaring these variables, we strongly recommend giving them a name descriptive of what they do.
  5. Create a loop which counts whether any of the variables have been selected and, if so, how many. This is done with the “FOR…” command.
  6. Set up the CASE statement to evaluate each number in the loop. If it finds a “True” variable, the NumberofCheckedVariables variable is increased by 1. (The list below contains both Boolean Modifiers and Boolean Variables) Note that each time the loop is executed, the VariableCounter is increased by 1. In this code, the loop continues until the Variable Counter reaches 10 at which point it stops looping.
  7. Create an error message indicating which error the user must correct in order to save the form. Below is the complete code which accomplishes this.
  8. Declare VariableCounter := 1;
    //Declare NumberOfCheckedVariables :=0 ;
    Declare NumberOfCheckedVariables := 0;
     FOR VariableCounter := 1 to 10  DO
       Case VariableCounter  Is 
            1 then if  DisplayModifierValue("UPS") = "YES" THEN NumberOfCheckedVariables := NumberOfCheckedVariables+1 endif
            2 then if  DisplayModifierValue("Overnight-Rush") =  "YES"THEN NumberOfCheckedVariables := NumberOfCheckedVariables +1 endif
            3 then if DisplayModifierValue("StandardUPS") = "YES"THEN NumberOfCheckedVariables := NumberOfCheckedVariables+1 endif
            4 then if commercialshipper  = TRUE THEN NumberOfCheckedVariables := NumberOfCheckedVariables+1 endif
            5 then if DisplayModifierValue("Deliver") = "YES"THEN NumberOfCheckedVariables := NumberOfCheckedVariables+1 endif
            6 then if GivetoSalesperson  = TRUE THEN NumberOfCheckedVariables := NumberOfCheckedVariables+1 endif
            7 then if DisplayModifierValue("UPS3DayAir") =  "YES"THEN NumberOfCheckedVariables := NumberOfCheckedVariables +1 endif
            8 then if DEL_CUSTOMERPICKUP_YN = TRUE THEN NumberOfCheckedVariables := NumberOfCheckedVariables +1 endif
            9 then if UseCustomerCarrier  = TRUE THEN NumberOfCheckedVariables := NumberOfCheckedVariables +1 endif
            10 then  if  DisplayModifierValue("USMAIL") = "YES" THEN NumberOfCheckedVariables := NumberOfCheckedVariables+1 endif
           ELSE NumberOfCheckedVariables 
       ENDCASE;
       VariableCounter = VariableCounter +1
    ENDFOR;
    IF NumberOfCheckedVariables  >1 THEN "Please Select Only 1 Shipping Method" Else 
        IF NumberOfCheckedVariables  =  0 THEN "Please Select Shipping Method" 
    Else "" ENDIF ENDIF

Contributor: Steve Gillispie, Acorn Sign Graphics

Date: 01/21/2010

Version: Control 4._

You could leave a comment if you were logged in.