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 Product Error 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 the If Statement or Case Statements 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. The Formula Builder provides this code in the “Control Loops” 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 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 CASE statement causes CFL to evaluate each of the "Boolean" 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.
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 code ===== Source ===== Contributor: Steve Gillispie, Acorn Sign Graphics Date: 01/21/2010 Version: Control 4._ ===== See Also ===== * Backlinks include_pagepage_componentbacklinks