Defining Validation Rules

This task is a step in Process of Adding Custom Objects.

In this topic, you add data validation rules to make sure the user enters information in the form correctly. For this example, assume an activity includes the following business requirements:

  • The Owner field must contain an owner.

  • The Planned Start field must contain a date.

  • The date in the Planned Complete field must not occur earlier than the date in the Planned Start field.

In this topic, you use the forms_12.xml file. For more information, see Correct Usage of the Forms File and Object ID.

To define validation rules

  • Create a validation_rules section for the form description. You add the following code to the forms_12.xml file:

    <form id="SBL Activity">
      <validation_rules>
        <rule message="Owner is required.">
          <expression>
            <![CDATA[item["Primary Owner Id"] != null]]>
          </expression>
          <asserted_control id="Owner"></asserted_control>
        </rule>
        <rule message="Planned Start is required" expression="Planned != null">
          <asserted_control id="0x20017"></asserted_control>
        </rule>
        <rule message="#msg_activity_planned_complete_validation">
          <expression>
            <![CDATA[
              item['Planned Completion']!=null ? item['Planned Completion'] >= 
              item['Planned'] : true;
            ]]>
          </expression>
          <asserted_control id="PlannedCompletion"></asserted_control>
        </rule>
      </validation_rules>