Hello Manisha. The empty View Form appears because workItemForm is currently attached to every approval, even when no areas were collected. I would suggest calculating areasDisplay in a separate step before the Approval and attaching the form only when that variable has a value.
Make sure the variable is declared once at the workflow level (if it is not already there):
<Variable name="areasDisplay"/>
Then add this step before Approval:
<Step name="Prepare Areas for Approval"
resultVariable="areasDisplay">
<Script>
<Source>
import java.util.Collection;
StringBuilder sb = new StringBuilder();
if (project != null &&
project.getExpansionItems() != null) {
for (ExpansionItem item : project.getExpansionItems()) {
if (item == null ||
!"areas".equals(item.getName()) ||
item.getValue() == null) {
continue;
}
Object value = item.getValue();
if (value instanceof Collection) {
for (Object area : (Collection) value) {
if (area != null &&
area.toString().trim().length() > 0) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(area.toString().trim());
}
}
} else {
String area = value.toString().trim();
if (area.length() > 0) {
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(area);
}
}
}
}
return sb.toString();
</Source>
</Script>
<Transition to="Approval"/>
</Step>
Also update any existing transition that currently goes directly to Approval so it routes through this step first:
<Transition to="Prepare Areas for Approval"/>
Then make the form conditional in the Approval step:
<Approval
mode="ref:approvalMode"
owner="call:buildCommonApprovals"
renderer="lcmWorkItemRenderer.xhtml"
send="identityDisplayName,identityName,approvalSet,flow,policyViolations,identityRequestId,areasDisplay">
<Arg name="workItemForm">
<Script>
<Source>
if (areasDisplay != null &&
areasDisplay.trim().length() > 0) {
return "Manager Access Details";
}
return null;
</Source>
</Script>
</Arg>
<Arg name="workItemType" value="Approval"/>
</Approval>
Remove the existing static entry:
<Arg name="workItemForm" value="Manager Access Details"/>
When areas are found, IIQ will attach the Manager Access Details form. When no areas were collected, workItemForm returns null, so the approval should render without the empty View Form option.
You can also remove the workflow.put() and wfcontext.getWorkflowCase().put() calls from your current script. The resultVariable="areasDisplay" on the preparation step stores the returned value as the workflow variable. (Editing Workflow XML, Approval Steps)
I would suggest doing a quick test in your environment to confirm the View Form button behavior when workItemForm evaluates to null, since that specific rendering is not explicitly called out in the docs. It should work, but worth verifying once.