I have a workflow launched via a quicklink, which is used by different user groups in my organization.
The workflow shows a form, the form displays some value.
Now I want to add a Next button in this form to go to next step in workflow. This Next button needs to be shown to some users and hidden for others.
Is there a way to achieve this? That is add a button to form in workflow where button is visible to some users and not visible to others.
To dynamically hide or remove a button based on a user’s group, use a function within a field validation script on a form. Ensure the field is marked as dynamic=true for the script to take effect. Here’s the approach to implement this:
Use context.getUserName() to retrieve the current user’s identity.
Determine the user’s group based on their identity.
Apply an if condition to hide or remove the button based on the group.
public void removeButtonByLabel(Form form, String label) {
List buttons = form.getButtons();
for (Button button : buttons) {
if (label.equals(button.getLabel())) {
form.remove(button);
break;
}
}
}
The logic is implemented in a field in the form like the following not on the button. I believe you might be able to achieve this without the dynamic=true. You are essentially hijacking the logic for the form in a field. Please try some trial & error.
<Field>
<Script>
<Source><![CDATA[
import sailpoint.object.Form;
import sailpoint.object.Form.Button;
import sailpoint.object.Identity;
Identity launcher = context.getObjectByName(Identity.class, context.getUserName());
if (logic to check if launcher has groups) {
removeButtonByLabel(form, "Next");
}
return "sample";
]]></Source>
</Script>
</Field>