Add limitations in field

Hi,
In my form I have added some limitations which are meant to check for specific inputs and reject them.
Also, in this field I have added a predefined value to help user type the name after a value.
I have implemented a check separately in order to prevent the user from submitting the form with only predefined value, but this particular check is not working somehow. Any suggesrions?

<Script>
        <Source>import sailpoint.object.*;
          import sailpoint.tools.Util;

          String accountName="";

          Object field8 = form.getField("accountType").getValue();

          if(field8 != null){
          String accountType = (String)field8;
          if(Util.isNotNullOrEmpty(accountType)){
          if("Service Account is type of NPA that is used by an automated process and is not used in an interactive way by a user".equalsIgnoreCase(accountType)) {
          accountName = "SVC-";
          }
          }
          } 
          return accountName;</Source>
      </Script>
      <ValidationScript>
        <Source>
          import java.util.regex.Pattern;
          import java.util.regex.Matcher;

          String regex = "(?i)Admin|Adm|Administrator|Root|Privileged|Priv|Super|Power|Pwr|PA|HPA|[@#\\$%&amp;*_=+ ]";
          Pattern pattern = Pattern.compile(regex);
          Matcher matcher = pattern.matcher(value);

          if(matcher.find()){

          return "Input String contains Non-Allowed Special Characters or SubStrings";
          }

          if(value.length()>20)
          {
          return "Length of Input should not be greater than 20";
          }
          else

          return null;
        </Source>
      </ValidationScript>

Hi @pctripathi - I see this line and wonder where are you setting the variable “value” at? I don’t see it in the script, are you setting it in another part of the workflow? The logic works for matching so making a guess the value is not properly setting.
Matcher matcher = pattern.matcher(value);

Hi @pctripathi

Can you share complete field entry, in order to understand further.

Hi @Arpitha1 @ryan_toornburg
I am adding code for the entire field for reference.
I have added predefined value under “Script” and field check under “ValidationScript” tag.

<Field displayName="Enter New Service Account Name" dynamic="true" name="ServiceAcctName" postBack="true" required="true" type="string">
      <Attributes>
        <Map>
          <entry key="hidden">
            <value>
              <Script>
                <Source>import sailpoint.object.Field;

                  Field f8 = form.getField("accountType");
                  String f8value = f8.getValue();
                  boolean hideField = false;

                  if(!("Service Account is type of NPA that is used by an automated process and is not used in an interactive way by a user".equalsIgnoreCase (f8value))) {

                  hideField= true; 
                  field.setRequired(false);
                  }
                  else {

                  field.setRequired(true);
                  }
                  return hideField;</Source>
              </Script>
            </value>
          </entry>
        </Map>
      </Attributes>
      <Script>
        <Source>import sailpoint.object.*;
          import sailpoint.tools.Util;

          String accountName="";

          Object field8 = form.getField("accountType").getValue();

          if(field8 != null){
          String accountType = (String)field8;
          if(Util.isNotNullOrEmpty(accountType)){
          if("Service Account is type of NPA that is used by an automated process and is not used in an interactive way by a user".equalsIgnoreCase(accountType)) {
          accountName = "SVC-";
          }
          }
          } 
          return accountName;</Source>
      </Script>
      <ValidationScript>
        <Source>
          import java.util.regex.Pattern;
          import java.util.regex.Matcher;

          String regex = "(?i)Admin|Adm|Administrator|Root|Privileged|Priv|Super|Power|Pwr|PA|HPA|[@#\\$%&amp;*_=+ ]";
          Pattern pattern = Pattern.compile(regex);
          Matcher matcher = pattern.matcher(value);

          if(matcher.find()){

          return "Input String contains Non-Allowed Special Characters or SubStrings";
          }

          if(value.length()>20)
          {
          return "Length of Input should not be greater than 20";
          }
          else

          return null;
        </Source>
      </ValidationScript>
    </Field>

@pctripathi Also, may I know what value you are entering in form, to expect a validation to be run ?

I have a predefined value in the field which is SVC- as you can see under “script” tag and I need to prevent the user submitting the form if they are going ahead with just SVC-.
Like SVC- is the starting credential and after that user should be writing the required name instead of just going further with pre defined value.

Also under “ValidationScript” tag I have defined few limitations which will not be accepted as the name.
I need to add one more condition for the case I have mentioned above.
Need help with that.

Under ValidationScript add this

if ("SVC-".equals(value)) {
        return "Input cannot be just 'SVC-'. Please provide a more specific name.";
      }

@pctripathi so your expectation is,

Case 1: If I type value as SVC-Admin, it should throw error as per validation
Case 2: If I type value as just SVC-, even in that case it should throw validation message
Case 3: If I type value as SVC-abcd, then it should go to next step without throwing any error message.

Is my understanding correct?

@Arpitha1
I needed solution for only case 2. Others are already implemented in the code I provided above.
I did figure it out. Thanks

1 Like