Validation Script in Form — End Date Should Not Be Earlier Than Start Date

I’m working on a Workflow Form in SailPoint IdentityIQ where I need to validate two date fields — Start Date and End Date.

My requirement is:

  • If the user selects an End Date that is earlier than the Start Date, the form should not submit.

  • It should display a validation error message to the user.

Here’s a simplified version of my form:

<Form name="CSV Path Input Form" type="Workflow">
  <Section name="Section 2">
    <Field displayName="Start Date" name="startdate" required="true" type="date"/>
    <Field displayName="End date" name="enddate" required="true" type="date">
      <ValidationScript>
        <Source>
          import java.util.Date;     
         Date end = (Date) value;
      Object startObj = form.getField("startdate").getValue();
      Date start = null;

      if (startObj instanceof Date) {
          start = (Date) startObj;
      }

      if (start == null) {
          errors.put("enddate", "Please select Start Date before End Date.");
          return false;
      }

      if (end != null && end.before(start)) {
          errors.put("enddate", "End Date cannot be earlier than Start Date.");
          return false;
      }

      return true;
    </Source>
  </ValidationScript>
</Field>
</Section>
  <Button action="next" label="Submit"/>
  <Button action="cancel" label="Cancel"/>
</Form>

but it threw this error:

Method getFieldValue(java.lang.String) not found in class 'sailpoint.object.Form'
1 Like

Hey @Viraj ,

I validated the logic and it works as expected. You should return a string message for validation failures instead of a boolean. This ensures the warning displays properly on the form.

<Step icon="Default" name="Initial Form" posX="123" posY="11">
  <Approval name="Initial Selection Form" owner="ref:launcher" return="identityModel" send="identityModel">
    <Arg name="workItemFormBasePath" value="identityModel"/>
    <Form name="CSV Path Input Form" type="Workflow">
      <Section name="Section 2">
        <Field displayName="Start Date" name="startdate" required="true" type="date"/>
        <Field displayName="End date" name="enddate" required="true" type="date">
          <ValidationScript>
            <Source>
            import java.util.Date;     
            Date end = (Date) value;

            Object startObj = form.getField("startdate").getValue();
            Date start = null;

            if (startObj instanceof Date) {
              start = (Date) startObj;
            }

            if (start == null) {
              // errors.put("enddate", "Please select Start Date before End Date.");
              return "Please select Start Date before End Date.";
            }

            if (end != null @and end.before(start)) {
              // errors.put("enddate", "End Date cannot be earlier than Start Date.");
              return "End Date cannot be earlier than Start Date.";
            }

            //return true;
            </Source>
          </ValidationScript>
        </Field>
      </Section>
      <Button action="next" label="Submit"/>
      <Button action="cancel" label="Cancel"/>
    </Form>
  </Approval>
  <Transition to="Analysis"/>
</Step>

hope that helps!

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.