Issue
- Whenever the API: http://localhost:8080/o/headless-admin-workflow/v1.0/workflow-tasks/assigned-to-me is executed, there are multiple loggers in the console which indicates that it is being executed every time.
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:
here users can define an expiration time to store the first information retrieved by a scripted assignment.Navigate to Control Panel > System Settings > CONTENT AND DATA > Workflow > Workflow Task Script
Additional Information
- Steps for testing purposes:
- Start server DXP 7.4 update 86
- Create a new user "user1" so that we have two users in our system (test and user1)
- Navigate to Applications> Workflow> Process Builder
- 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>- 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 - Now, navigate to Control Panel> Objects and create one object with one custom field of 'Text' type.
- Go to Applications> Workflow> Process Builder> Workflows>Configuration and enable this created workflow for the created object.
- Go to the page and add an object widget to test this behavior
- 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
- 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
- Use postman client, with basic auth : username: user1@gmail.com, password: test (as per my local)
- 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.