Trying to use a rule as a reference in a workflow

My Rule:
if (arguments == null) {
throw new GeneralException(“arguments map is null!”);
}

// Get input from arguments
String identityName = (String) arguments.get(“identityName”);

String appName = “AD”;

// Get identity object
Identity employee = context.getObject(Identity.class, identityName);
Identity identityobj = context.getObject(Identity.class, employee.getName());

// Create provisioning plan
ArrayList accRequestList = new ArrayList();
ProvisioningPlan plan = new ProvisioningPlan();
plan.setIdentity(identityobj);

AccountRequest adAccountRequest = new AccountRequest();
Application application = context.getObject(Application.class, appName);

adAccountRequest.setApplication(application.getName());
adAccountRequest.setOperation(AccountRequest.Operation.Create);

// Add attributes
adAccountRequest.add(new AttributeRequest(“givenName”, Operation.Add, employee.getFirstname()));
adAccountRequest.add(new AttributeRequest(“sn”, Operation.Add, employee.getLastname()));
adAccountRequest.add(new AttributeRequest(“mail”, Operation.Add, employee.getEmail()));
adAccountRequest.add(new AttributeRequest(“department”, Operation.Add, employee.getStringAttribute(“department”)));
adAccountRequest.add(new AttributeRequest(“memberof”, “CN=AD-IND,CN=Users,DC=IDMITGURU,DC=COM”));

accRequestList.add(adAccountRequest);
plan.setAccountRequests(accRequestList);

// Compile and execute
Provisioner provisioner = new Provisioner(context);
provisioner.compile(plan);
provisioner.execute();

===================================================

=============================

My Workflow:

<?xml version='1.0' encoding='UTF-8'?> import java.util.HashMap; import sailpoint.object.Rule;
    Map args = new HashMap();
    args.put("identityName", identityName);

    Rule ruleObj = context.getObjectByName(Rule.class, "Rule_Create_AD_AccountPlan1");

    Object result = context.runRule(ruleObj, args);

    return result;
  </Source>
</Script>
<Transition to="Access Request"/>

Please let me know how to use rule as a reference in a workflow

Hi @SrikrishnaB ,

pleaes kindly reference the rule (library) you want to utilize.
You’ll be able to access the rule’s “methods” within your workflow.

    Required for the call to auditManualAction in the after script. 
  -->
  <RuleLibraries>
    <Reference name="Approval Library" class="sailpoint.object.Rule"/>
  </RuleLibraries>

You may want to check the example workflows in IIQ to better understand the functionality.

Best regards,
Daniel

Hello @SrikrishnaB

You need to have the arguments defined in the rule signature to work this. Refer the below sample code

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule created="1754384592140" id="0a2deca798511e48819879786d0c56c3" language="beanshell" name="Test Run Rule">
  <Description>Test Run Rule</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="identityName">
        <Description>The application whose data file is being processed.</Description>
      </Argument>
    </Inputs>
    <Returns>
      <Argument name="Endpoint or Updated Map which contains requestEndPoint and connectorStateMap">
        <Description>Updated Endpoint or information Map which contains endpoint and connectorStateMap</Description>
      </Argument>
    </Returns>
  </Signature>
  <Source>
return identityName;

</Source>
</Rule>

Another rule from where i am executing the above rule.

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule  language="beanshell" modified="1754384746053" name="Test Rule" significantModified="1754384746053">
  <Description>

  </Description>
  <Signature>
    <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>
    </Inputs>
  </Signature>
  <Source>
  
  import sailpoint.object.*;
  
   Map args = new HashMap();
    args.put("identityName", "TestIdentity");

    Rule ruleObj = context.getObjectByName(Rule.class, "Test Run Rule");

    Object result = context.runRule(ruleObj, args);

    return result;
  
</Source>
</Rule>

Let me know if you need any further help.

@SrikrishnaB You no need to use arguments. Instead, you can use identityName.

Remove below line

String identityName = (String) arguments.get(“identityName”);

Add void and null check on identityName as below.

if(identityName != void && identityName != null){
//Insert your code here. Eg..

String appName = “AD”;

// Get identity object
Identity employee = context.getObject(Identity.class, identityName);

// Create provisioning plan
ArrayList accRequestList = new ArrayList();
ProvisioningPlan plan = new ProvisioningPlan();
plan.setIdentity(employee);

AccountRequest adAccountRequest = new AccountRequest();
Application application = context.getObject(Application.class, appName);

adAccountRequest.setApplication(application.getName());
adAccountRequest.setOperation(AccountRequest.Operation.Create);

// Add attributes
adAccountRequest.add(new AttributeRequest(“givenName”, Operation.Add, employee.getFirstname()));
adAccountRequest.add(new AttributeRequest(“sn”, Operation.Set, employee.getLastname()));
adAccountRequest.add(new AttributeRequest(“mail”, Operation.Set employee.getEmail()));
adAccountRequest.add(new AttributeRequest(“department”, Operation.Set, employee.getStringAttribute(“department”)));
adAccountRequest.add(new AttributeRequest(“memberof”, Operation.Add, “CN=AD-IND,CN=Users,DC=IDMITGURU,DC=COM”));

accRequestList.add(adAccountRequest);
plan.setAccountRequests(accRequestList);

// Compile and execute
Provisioner provisioner = new Provisioner(context);
provisioner.compile(plan);
provisioner.execute();
}