Thursday 2 July 2020

How to get the value of other fields in a form in validation scripts.

I have two fields Location & sub-location and based on the value in location, the sublocation should allow to have the value from selected value from the lists and on having a different value in the field should give the customized message.

Eg,    Location India and corresponding sublocation is Bangalore,Hyderabad,Pune




The below rule can have multiple If statement, based on your requirement.





//validation variable comes in as 'value'
                import sailpoint.tools.Message;
                String Val = form.getField("Location").getValue();
                System.out.println("Value is :" + Val);
                List messages = new ArrayList();
                String input = (String)value;
                System.out.println("Value :" + input);
// Check===================================
   if(Val.equals("India")) {
   List loc = new ArrayList();
     loc.add("Bangalore");
     loc.add("Pune");
     loc.add("Hyderabad");
        int j=0;   
     for(String item : loc){
       if( input.equals(item)){
            j++;       

                   }          
        }               

      if(j!=1) {
                Message msg = new Message();
                     msg.setKey("Allowed value are Bangalore,Pune,Hyderabad");
                     messages.add(msg);

                }       

          }
     return messages;

No comments:

Post a Comment

ServiceNow onboarding Sailpoint