Legacy Knowledge Base
Published Jun. 30, 2025

Headless Admin Workflow APIs executing groovy scripts for scripted task assignment

Written By

Kanchan Bisht

How To articles are not official guidelines or officially supporteddocumentation. They are community-contributed content and may not alwaysreflect the latest updates to Liferay DXP. We welcome your feedback toimprove How to articles!

While we make every effort to ensure this Knowledge Base is accurate, itmay not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with anyfeedback or concerns.

Legacy Article

You are viewing an article from our legacy "FastTrack"publication program, made available for informational purposes. Articlesin this program were published without a requirement for independentediting or verification and are provided "as is" withoutguarantee.

Before using any information from this article, independently verify itssuitability for your situation and project.

Issue

Environment

  • Liferay DXP 7.4

Resolution

  • This is expected behavior because when we perform a request for the endpoint mentioned we need to retrieve action inside the response to provide HATEOAS, so we get the assignee (or candidate assignees) of the task to know if such action is available for this user (user1 in this case), in this case we need to evaluate the script to know this information this is why we’re executing five times.

    Also, if users would like to understand the code, they may refer to this and this.

    Now, the following is the step which might help you to avoid so many logs:
    Navigate to Control Panel > System Settings > CONTENT AND DATA > Workflow > Workflow Task Script
    here users can define an expiration time to store the first information retrieved by a scripted assignment.

Additional Information

  • Steps for testing purposes:
    1. Start server DXP 7.4 update 86
    2. Create a new user "user1" so that we have two users in our system (test and user1)
    3. Navigate to Applications> Workflow> Process Builder
    4. Add a new workflow by adding the provided .XML
    <?xml version="1.0"?>
    <workflow-definition
    xmlns="urn:liferay.com:liferay-workflow_7.4.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:liferay.com:liferay-workflow_7.4.0 http://www.liferay.com/dtd/liferay-workflow-definition_7_4_0.xsd"
    >
    <version>17</version>
    <state>
    <name>668db35c-b4b4-4317-bfc9-61305beb094d</name>
    <description>Begin a workflow.</description>
    <metadata>
    <![CDATA[
    {
    "xy": [
    -69,
    87
    ]
    }
    ]]>
    </metadata>
    <initial>true</initial>
    <labels>
    <label language-id="en_US">
    Start
    </label>
    </labels>
    <transitions>
    <transition>
    <labels>
    <label language-id="en_US">
    Transition Label
    </label>
    </labels>
    <name>b261d801-9ee4-4f82-983a-6148137128bd</name>
    <target>6acf1f13-c895-4904-a2e7-9c68e6d9c045</target>
    <default>true</default>
    </transition>
    </transitions>
    </state>
    <state>
    <name>822e1b6b-fec6-4b9e-849c-579b8f5914b4</name>
    <description>Conclude the workflow.</description>
    <metadata>
    <![CDATA[
    {
    "xy": [
    624.1597166683956,
    348.18265251631755
    ],
    "terminal": true
    }
    ]]>
    </metadata>
    <labels>
    <label language-id="en_US">
    End
    </label>
    </labels>
    </state>
    <task>
    <name>6acf1f13-c895-4904-a2e7-9c68e6d9c045</name>
    <description>Ask a user to work on the item.</description>
    <metadata>
    <![CDATA[
    {
    "xy": [
    332.903564453125,
    116.55914306640625
    ]
    }
    ]]>
    </metadata>
    <assignments>
    <scripted-assignment>
    <script>
    <![CDATA[
    import com.liferay.portal.kernel.workflow.WorkflowConstants;
    import com.liferay.portal.kernel.util.GetterUtil;
    import com.liferay.portal.kernel.service.UserLocalServiceUtil;
    import com.liferay.portal.kernel.model.User;
    import com.liferay.portal.kernel.log.Log;
    import com.liferay.portal.kernel.log.LogFactoryUtil;
    Log LOGGER = LogFactoryUtil.getLog(User.class);
    long companyId = GetterUtil.getLong((String) workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
    LOGGER.info("added-task");
    println("user");
    User l1User = UserLocalServiceUtil.getUserByScreenName(companyId, "user1");
    users = new ArrayList<>();
    LOGGER.info("added-task011");
    users.add(l1User);
    ]]>
    </script>
    <script-language>groovy</script-language>
    </scripted-assignment>
    </assignments>
    <labels>
    <label language-id="en_US">
    Task
    </label>
    </labels>
    <transitions>
    <transition>
    <labels>
    <label language-id="en_US">
    Transition Label
    </label>
    </labels>
    <name>fe0273df-7cc7-4bbc-a8fd-40037a6db5bd</name>
    <target>822e1b6b-fec6-4b9e-849c-579b8f5914b4</target>
    <default>true</default>
    </transition>
    </transitions>
    </task>
    </workflow-definition>
    1. Add the category at the Info level: com.liferay.portal.kernel.model.User to get the loggers at the time of workflow assigned to user1
    2. Now, navigate to Control Panel> Objects and create one object with one custom field of 'Text' type.
    3. Go to Applications> Workflow> Process Builder> Workflows>Configuration and enable this created workflow for the created object.
    4. Go to the page and add an object widget to test this behavior
    5. Whenever an object is created here, this will go to the pending state and we can check the console for the loggers.

    Outcome: When a workflow triggers, we can expect to receive a hardcoded message on the console as well as logs

    1. Now, navigate to localhost:8080/o/api to get the Headless API: http://localhost:8080/o/headless-admin-workflow/v1.0/workflow-tasks/assigned-to-me
    2. Use postman client, with basic auth : username: user1@gmail.com, password: test (as per my local)
    3. send request (Get: http://localhost:8080/o/headless-admin-workflow/v1.0/workflow-tasks/assigned-to-me)and you will get a response with 200 status.

    Outcome: Whenever we execute this API, there are multiple loggers in the console or we can say there is a hardcoded message on the console that is coming for every call even though this task is already assigned to user1.

Did this article resolve your issue ?

Legacy Knowledge Base