Share all details about your problem, including any error messages you may have received.
Hi all,
I have a form being called as part of a workflow and I would like on click of the submit button a custom rule will be called. Can anyone kindly advise?
I think it can be done two ways .
Approach 1 - whatever you want to do , put that functionality in a method . Reference that rule in this workflow using below tags after variables -
On the basis of the form action button call that particular method . It should get the work done .
Approach 2 - You can call the rule using runrule api from workflow source . below is the code snippet which can be used for same -
define the signature with inputs in your Rule as per below example -
<Description>Test Rule</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>
<Argument name="var1">
<Description>
test variables
</Description>
</Argument>
<Argument name="var2">
<Description>
test variables
</Description>
</Argument>
</Inputs>
</Signature>
Gather the data from Form in Workflow and pass in the rule in these variables . Below is the sample code -
Hi @harsh_gupta4 , the code you shared is to be placed in the rule? However, from the workflow/form what do I need to do to pass the value down to the rule.
The order is Workflow → Form → Rule?
The part I am not able to do is the rule reading the form values
The code which i have shared place in to workflow , Follow below steps -
Step 1 - whatever form you defined in workflow , it should have return values . once form get actioned , set those values in workflow variable.
Step2 - Create a new step in workflow .
Step3 - In Workflow step put the code i provided , pass those variables in place of “var1” and “var2” etc . as per your naming convention.
it should execute the rule and pass those variables in the Rule .
Hi @harsh_gupta4 , do you have a simple example to share? For all 3 components? I’m still quite confused because I am unable to retrieve the values from the form submitted in the rule.
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE Rule PUBLIC "sailpoint.dtd" "sailpoint.dtd">
<Rule language="beanshell" name="Sample-FormSubmissionRule" type="Workflow">
<Description>A rule used by a Workflow to determine a step action or variable value.
Note that an Attributes map of all variables from the current WorkflowContext, merged with the arguments from the Step, is also passed into the workflow rule.</Description>
<Signature returnType="Object">
<Inputs>
<Argument name="log" type="org.apache.commons.logging.Log">
<Description>
The log object associated with the SailPointContext.
</Description>
</Argument>
<Argument name="context" type="sailpoint.api.SailPointContext">
<Description>
A sailpoint.api.SailPointContext object that can be used to query the database if necessary.
</Description>
</Argument>
<Argument name="wfcontext">
<Description>
The current WorkflowContext.
</Description>
</Argument>
<Argument name="handler">
<Description>
The workflow handler associated with the current WorkflowContext.
</Description>
</Argument>
<Argument name="workflow">
<Description>
The current Workflow definition.
</Description>
</Argument>
<Argument name="step">
<Description>
The current Step.
</Description>
</Argument>
<Argument name="approval">
<Description>
The current Approval.
</Description>
</Argument>
<Argument name="item">
<Description>
The WorkItem being processed.
</Description>
</Argument>
</Inputs>
<Returns>
<Argument name="Object">
<Description>
The result of the workflow rule; dependent on the rule itself.
</Description>
</Argument>
</Returns>
</Signature>
<Source>
log.info("Entered the Sample-FormSubmissionRule ");
log.info("Submitted firstname : " + firstname);
log.info("Submitted lastname : " + lastname);
log.info("Exited the Sample-FormSubmissionRule");</Source>
</Rule>
As code provided by you , I have modified it and put one extra sample rule for your reference which you can replace by your rule . Please note - it is rough code and needs to be further optimized which you can do as per your requirement . I have just quickly wrote down here in community itself so there might be some error , you can test on your end and fix minor issues . below is the end to end sample code -
You cannot change the value of lastApprovalState it will be populated with only two values ‘Finished’ when form is submitted and ‘Rejected’ when the user clicks Back in Form.
Hi @Chathurya , thank you for replying. Then would it be possible to get the work item id in the rule? As I would like to pass the value to an email being triggered from the rule.
Append this code in Form in Workflow object from debug page and modify the return variable in form in workflow to include the returned variable ‘workItemName’ to use it later in rule.