Get Rule Under AllowedValuesDefinition Tag

In my form’s field I had written a script under allowedValuesDefinition tag.

I have moved that piece of script in a rule file and referencing it using below code.

<AllowedValuesDefinition>
        <RuleRef>
          <Reference class="sailpoint.object.Rule"  name="Rule Selection"/>
        </RuleRef>
      </AllowedValuesDefinition>

Also I have added a boolean in the rule file which I want to mention true or false in the AllowedValuesDefenition tag, so based on the condition one additional filter will be applied else not.
For this I have mentioned an if condition in my rule file.
I want to change that boolean to true or false at form level.

How can I do this.
I am adding the rule file below.

<Source>
  import sailpoint.object.Identity;
  import sailpoint.object.Filter;
  import sailpoint.object.QueryOptions;
  import sailpoint.tools.Util;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Iterator;

    boolean filterByManager;
    List selectedNPIdentityList = new ArrayList();
    QueryOptions queryOptions = new QueryOptions();

    // Common filters for both cases
    queryOptions.addFilter(Filter.eq("cwtype", "NPIdentity"));
    queryOptions.addFilter(Filter.eq("workertype", "NPIdentity"));

    // Add manager filter only for self selection
    if(filterByManager) {
      Identity launcher = context.getObjectByName(Identity.class, context.getUserName());
      queryOptions.addFilter(Filter.eq("manager.name", launcher.getName()));
    }

    Iterator it = context.search(Identity.class, queryOptions);
    while (it.hasNext()) {
      Identity identity = (Identity) it.next();
      String firstName = identity.getAttribute("firstname");
      String lastName = identity.getAttribute("lastname");
      String ssoId = identity.getAttribute("workerid");

      if (Util.isNotNullOrEmpty(firstName) &amp;&amp; Util.isNotNullOrEmpty(lastName) &amp;&amp; Util.isNotNullOrEmpty(ssoId)) {
        String displayName = String.format("%s %s (%s)", firstName, lastName, ssoId);
        selectedNPIdentityList.add(displayName);
      }
    }

    return selectedNPIdentityList;
  </Source>

Hey @pctripathi ,

you can add directly source code here:

<AllowedValuesDefinition>
              <Script>
                <Source><![CDATA[

                ]]></Source>
              </Script>
</AllowedValuesDefinition>

Hi @abartkowski
I am aware of that but since I am going to use the same source code in many of the upcoming forms, I have created this rule file.

For now I have added a condition in the rule file itself which will check for the field and behave accordingly.
Its working fine.
Open for any new suggestion.

This code is working on my IIQ instance:

<AllowedValuesDefinition>
        <RuleRef>
          <Reference class="sailpoint.object.Rule" name="Rule Selection"/>
        </RuleRef>
      </AllowedValuesDefinition>
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Rule Selection">
  <Description></Description>
  <Signature returnType="Object">
    <Inputs>
      <Argument name="log">
        <Description>
          The log object associated with the SailPointContext.
        </Description>
      </Argument>
      <Argument name="context">
        <Description>
          A sailpoint.api.SailPointContext object that can be used to query the database if necessary.
        </Description>
      </Argument>
      <Argument name="identity">
        <Description>
          The Identity object being provisioned.
        </Description>
      </Argument>
      <Argument name="form">
        <Description>
          The Form object for the provisioning plan.
        </Description>
      </Argument>
      <Argument name="field">
        <Description>
          The Field object being analyzed.
        </Description>
      </Argument>
    </Inputs>
    <Returns>
      <Argument name="value">
        <Description>
          An Object (possibly a Collection) of the allowed values for the given
          field.
        </Description>
      </Argument>
    </Returns>
  </Signature>
  <Source>
//add necessary imports here
    List mgr = new ArrayList();
			mgr.add("Test1");
			mgr.add("Test2");
			
			return mgr;
  </Source>
</Rule>