SailPoint IIQ – How to Retrieve and Log the Auto-Generated WorkItem Name Before an Approval Step Pauses the Workflow?

Hi Everyone,

I have a workflow in SailPoint IdentityIQ with an Approval step configured as follows:

<Step icon="Approval" name="ApprovalStep">
    <Approval mode="serial" return="" send="">
        <Arg name="workItemDescription" value="string:Request for User: .. "/>
        <Arg name="workItemType" value="Approval"/>
    </Approval>
</Step>

When the workflow reaches this step, IIQ creates a WorkItem and automatically generates its name, for example: 000003523

My requirement:

I want to retrieve this auto-generated WorkItem name and log it immediately after the WorkItem is created, but before the workflow pauses and waits for the approver’s decision.

The challenge:

  • The Approval step creates the WorkItem and suspends the workflow until the approval is completed.
  • Any subsequent workflow step will execute only after the approval process resumes.
  • Therefore, I cannot use a step after the Approval step to log the WorkItem name at the required time.

My questions:

  1. Is there a way to retrieve the generated WorkItem name during the execution of the Approval step?
  2. Is there a recommended way to log the WorkItem name immediately after its creation, without waiting for the approval to complete?

I would appreciate any suggestions or code examples for achieving this in SailPoint IIQ.

Thanks in advance!

An interceptor script can be added to approval steps in workflows to act on the generated approval/workitem

<Approval>
  <Arg name="argName" value="argValue"/>
  <InterceptorScript>
    <Source>
      if (sailpoint.object.Workflow.INTERCEPTOR_START_APPROVAL.equals(method))
      {
        log.info("Workitem name is: " + item.getName());
      }
    </Source>
  </InterceptorScript>
</Approval>

Hi @BhuvaneshGeddam

I tried logging method, approval, workflow, and item in the InterceptorScript. The logs show that method is startApproval and the workflow object is available, but item is null.

<Approval>
	<Arg name="argName" value="argValue"/>
	<InterceptorScript>
		<Source>
			if (sailpoint.object.Workflow.INTERCEPTOR_START_APPROVAL.equals(method)) {
				log.info("method= " + method);
				log.info("approval= " + approval);
				log.info("workflow= " + workflow);
                log.info("item= " + item);
			}
		</Source>
	</InterceptorScript>
</Approval>

Logs were:

method=startApproval
approval=sailpoint.object.Workflow$Approval@eb13433 
workflow=sailpoint.object.Workflow@790af4be[id=<null>, name= "Test"]
item=null

Could you please suggest whether the WorkItem has not been created yet or if I’m using the wrong variable to access it?

Hello @shsakshi ,

Can you check if the value ‘000003523’ is stored in the Identity Request object and if available you can get the value from the IdentityRequest

As the approval has been started, I believe the workitem may not be created yet, there is another method constant sailpoint.object.Workflow.INTERCEPTOR_OPEN_WORK_ITEM, it should work as this is invoked immediately after the workitem creation. If it doesn’t work, kindly search for the INTERCEPTOR_ fields in workflow javadoc and use as needed.

Hi @Chathuryas

There is no IdentityRequest reference in the WorkItem, as it was created directly by the workflow engine.

Hi @BhuvaneshGeddam

After changing the interceptor to sailpoint.object.Workflow.INTERCEPTOR_OPEN_WORK_ITEM, the logs show that item is available, but its name is still null.

item=[WorkItem:[name=null],[type=Approval],[state=null],[level=Normal],[requester=<abc>], ....]

I also tried INTERCEPTOR_PRE_ASSIMILATION and INTERCEPTOR_POST_ASSIMILATION, but the code was not executed.

Is there any interceptor that runs before the workflow pauses, after the WorkItem is created and its name is generated? Or is there another way to access the generated WorkItem name at this stage?

I didn’t anticipate this, if at openWorkItem the workitem doesn’t have name, id then it means that the workitem is not yet saved.
And the pre, post assimilation are invoked after an action has been taken. So it makes sense that the script didn’t run as you would be checking the logs before taking the action on the workitem.

Try without checking for specific method equivalence, just check if the item is not null and try to get the name, I don’t think it will return anything, but just to rule out.
eg:

<Approval>
  <Arg name="argName" value="argValue"/>
  <InterceptorScript>
    <Source>
      if (item != null)
      {
        log.info("method= " + method);
        log.info("item= " + item);
      }
    </Source>
  </InterceptorScript>
</Approval>

There will be a validation script as well, but AFAIK it will run only if someone opens/submits the workitem, but still worth a try.
eg:

<ValidationScript>
  <Source>
        log.info("Workitem name is: " + item.getName());
  </Source>
</ValidationScript>

There is one more way, which is a bit unconventional but may work. First check if the log variable $log would be available in approval email template, if yes then log the workitem name from there.
If it’s not available in the email template, then a new workflow variable has to be created for the log which has to be initialized and it will be subsequently available in the email template from which the workitem name can be logged.
eg:

EmailTemplate object
<EmailTemplate name="Approval Email Template">
  <Body><![CDATA[<html><body>
    $log.info("Test"); ## check if the default log works, I don't think so
    $customWfLog.info("Test"); ## WF logger</body></html>]]>
  </Body>
</EmailTemplate>

Workflow variable addition
<Workflow>
  <Variable name="customWfLog">
    <Script>
      <Source>
        return org.apache.commons.logging.LogFactory.getLog("loggername");
      </Source>
    </Script>
  </Variable>
</Workflow>

But the logger line has to be added in multiple emailtemplates so not a scalable solution.

There is a complicated solution of creating a separate thread to run rule/task with a short delay and the workflowcaseid as input from which current step can be found and the workitemid.

You have to decide if the requirement to log the workitem name needs this complexity, if the business requirement is something else and getting the workitem name is an interim step then alternatives can be explored.

Hi @BhuvaneshGeddam

The output for the following code:

<Approval>
  <Arg name="argName" value="argValue"/>
  <InterceptorScript>
    <Source>
      if (item != null)
      {
        log.info("method= " + method);
        log.info("item= " + item);
      }
    </Source>
  </InterceptorScript>
</Approval>

Output:

method= openWorkItem
item=[WorkItem:[name=null],[type=Approval],[state=null],[level=Normal],[requester=<abc>], ....]

I configured a EmailTemplate for testing purpose and fetch $workItem.name, its giving correct WorkItem Name: 000003523

I want to log the WorkItem name before the user opens it or takes any action, similar to how it is available in the email template. The purpose is to identify which WorkItem the user needs to open and approve or reject to proceed with the process.

Can you also try the validationscript and also the log method in the email template?

For the Validation Script:

<Approval>
  <Arg name="argName" value="argValue"/>
  <ValidationScript>
    <Source>
      if (item != null)
      {
        log.info("method= " + method);
        log.info("item= " + item);
      }
    </Source>
  </ValidationScript>
</Approval>

The logs are generated when the user takes an action (Approve/Reject).

Output:

method= void
item= [WorkItem: [name =  000003523], [type = Approval], [state = Rejected], [level = Normal], .....]

I configured a EmailTemplate for testing purpose and fetch $workItem.name, its giving correct WorkItem Name: 000003523

<Approval>
  <Arg name="argName" value="argValue"/>
  <Arg name="workItemnotificationTemplate">
         <Script>
             <Source>
                    return "Approval notification"
            </Source>
        </Script>
    </Arg>
</Approval>

Email Template: Approval notification.xml
log.info("Req Id: " + $workItem.name);

Output
Req Id: 000003523

I guess you are providing wrong example in the validation script in here, but the actual test is correct.

But the email template test is not as mention here.

Please check and retry