How to use a Catalog Form Field-value in a Policy condition

Document ID : KB000125350
Last Modified Date : 28/01/2019
Show Technical Document Details
Introduction:
N/A
Background:
N/A
Environment:
Windows
Instructions:
Please see the following to get an example as such.
 
Defined in the SC>Catalig UI:
Offering         - "Employee Recognition"
Form name        - "TestForm"
Form field id    - "discount_code"
Form field value - "TEST"

My policy condition were:
$(anySoWith('status', lteq, 800) && _.service.code=='ER' && _.sog['Employee Recognition'].serviceoption[1].form['TestForm'].discount_code=='TEST')
$(anySoWith('status', lteq, 800) && _.service.code=='ER' && _.sog['Employee Recognition'].serviceoption[1].form['TestForm'].discount_code!='TEST')

As you can see, in one condition, I'm testing whether the field value is set to the same as the value attribute 
(discount_code=='TEST') or if it's not the same (discount_code!='TEST').

If the check box is ticked,     discount_code=='TEST' is true.
If the check box is not ticked, discount_code!='TEST' is true.

Note:
You can create policy conditions based on form fields using the following format:
$(_.sog[sogname].serviceoption[rownum].form[form-name].value of _id attribute string-operator 'value of value attribute')

Unfortunately you can only leverage string operators, equal and not equal, as form data is stored as strings.
Which is noted under 'Conditions Based on the Fields of Form Designer Forms' in the Admin Guide:

Important! 
The Form Designer stores the values for all fields in string format. 
Even the fields that contain numeric input that users or the Catalog system specify are stored in string format. 
Therefore, conditions that are based on Form Designer fields can use only the comparison operators suitable for strings: 
equal (==) and not equal (!=). 
Moreover, always enclose these values in quotation marks, because they are always strings.

You could however create an API plugin to convert/compare the value of the field 
and assign the task appropriately when the field is not empty. 
For more information on API plugins with policies you can refer to 'How to Write and Use API Plug-ins for Policies' in the Admin Guide.