Workflow form to include validation before submission

Which IIQ version are you inquiring about?

8.4

Share all details about your problem, including any error messages you may have received.

Hi all, I currently have a workflow which has a form and will call a rule which executes some API call. May I check if I can do any field validation before the transition to execute rule? So upon submit, for example, if email is not in correct format it will stay on the form for user to rectify the mistake before submitting again then the rule will execute.

Any help is greatly appreciated! :slight_smile:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Workflow PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Workflow explicitTransitions="true" name="Self Service View Workflow - Vendor">
  <!-- Define all required variables -->
  <Variable input="true" name="launcher"/>
  <Variable name="alias"/>
  <Variable name="department"/>
  <Variable name="email"/>
  <Variable name="firstName"/>
  <Variable name="lastName"/>
  <Variable name="mobileNumber"/>
  <Variable name="username"/>
  <Variable name="ruleResult"/>
  <Variable initializer="true" name="transient"/>
  
  <Step icon="Start" name="Start" posX="36" posY="82">
    <Transition to="Display Form"/>
  </Step>
  <Step action="call:addMessage" name="MessageToUser" posX="81" posY="150">
    <Arg name="message" value="Request is in progress of submission. Please click on 'My Work -> Access Requests' later to view its Request ID, details and status."/>
    <Transition to="Execute Rule"/>
  </Step>
  <Step icon="Default" name="Display Form" posX="128" posY="84">
    <Approval name="**** Account Invite - Vendor" owner="script:return context.getUserName();" return="alias,department,firstname,lastname,email,mobile,username" send="">
      <Form name="**** Account Guest Invite">
        <Attributes>
          <Map>
            <entry key="pageTitle" value="**** Account Invite (Vendor)"/>
          </Map>
        </Attributes>
        <Section name="User Details ">
		  <Field displayName="Alias" name="alias" type="string" required="false"/>
		  <Field displayName="Department" name="department" type="string" required="false"/>
          <Field displayName="First Name" name="firstname" type="string" required="true"/>
          <Field displayName="Last Name" name="lastname" type="string" required="true"/>
          <Field displayName="Email" name="email" type="string" required="true" helpKey="Check on for valid email domains"/>
          <Field displayName="Mobile Number" name="mobile" type="string" required="true"/>
          <Field displayName="Username" name="username" type="string" required="true"/>
        </Section>
        <Button action="next" label="Submit"/>
        <Button action="back" label="Back"/>
      </Form>
    </Approval>
    <Transition to="Execute Rule">
      <Script>
        <Source> boolean result =false; if(lastApprovalState.equalsIgnoreCase("Finished")){ result = true; } return result;</Source>
      </Script>
    </Transition>
  </Step>
  <Step action="rule:**** Account Invite - Vendor" icon="Default" name="Execute Rule" posX="255" posY="140" resultVariable="response">
    <Transition to="Confirmation step"/>
</Step>
<Step icon="Default" name="Confirmation step" posX="255" posY="140">
<Arg name="response" value="ref:response"/>
<Script>
<Source> 
import javax.faces.application.FacesMessage;

List currentMessages = httpSession.getAttribute("sailpoint.web.PageCodeBase.sessionMessages");
List myMessages = new ArrayList();

if (response != null &amp;&amp; response.get("email") != null) {
    FacesMessage myMessage = new FacesMessage(
        FacesMessage.SEVERITY_INFO,
        "**** Account Invite sent successfully.",
        "**** Account Invite sent successfully."
    );
    myMessages.add(myMessage);
} else {
    FacesMessage myMessage = new FacesMessage(
        FacesMessage.SEVERITY_ERROR,  // Changed to ERROR for unsuccessful cases
        "**** Account Invite creation request failed. Please try again.",
        "**** Account Invite creation request failed. Please try again."
    );
    myMessages.add(myMessage);
}

httpSession.setAttribute("sailpoint.web.PageCodeBase.sessionMessages", myMessages);
</Source> 
</Script>
<Transition to="Stop"/>
</Step>
  <Step icon="Stop" name="Stop" posX="342" posY="76"/>
</Workflow>

Hi @shijingg ,

Use the ValidationScript in the form field. Please refer below.

		  <Field displayName="Email" name="email" type="string" required="true" helpKey="Check on for valid email domains">
    <Description>Enter a valid email address with approved domain</Description>
    <ValidationScript>
        <Source>
            import sailpoint.object.*;
            import sailpoint.tools.GeneralException;
            import org.apache.commons.lang.StringUtils;
            import sailpoint.tools.Message;
            import java.util.List;
            import java.util.Arrays;
            import java.util.regex.Pattern;

            Message msg = new Message();
            
            if (email != null @and !StringUtils.isEmpty(email.trim())) {
                String emailValue = email.trim();
                
                String domain = emailValue.substring(emailValue.lastIndexOf("@") + 1).toLowerCase();

                List validDomains = Arrays.asList(
                    "company.com",
                    "organization.org", 
                    "business.net",
                    "enterprise.com",
                    "corp.com"
                );

                if (!validDomains.contains(domain)) {
                    msg.setKey("Email domain '" + domain + "' is not allowed. Please use an approved domain.");
                    return msg;
                }
                
            }
            
            return null;
        </Source>
    </ValidationScript>
</Field>

Hi @shijingg

In the field Edit Options you have a section - Value Settings:

There in the Validation part you can select rule or script, and provide the validation logic based on your requirement.

Before directly executing the workflow and checking for the errors that may encounter in the selected script or rule, try executing that rule in the debug page and check for all test case scenarios, if every thing seems to work as expected, then you can select that rule in this validation section and then try executing the workflow.

I hope this helps.

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