I've seen few K2ers asking how to refresh the Inbox when a task has been actioned via a SmartForm in K2 Five/Cloud Workspace.
Current behaviour:
If you noticed that whenever you action a task in the workspace, you will have to manually refresh the Inbox in order for the task to disappear.
If the end user clicks on the actioned task again, an expected error will appear as the task has already been actioned by the user:
Solution - K2 Five:
In K2 Five it is not complicated to implement, you can trigger the refresh function using JavaScript.
The script will be executed after the button click that actions your task
Implementation:
Script
<script>window.top.parent.$("lid$='_refreshInput']").click();</script>
1- Add a data label control to your task form and make sure Literal property is checked and Prevent XSS is unchecked
2- Add two transfer data action after the Worklist item action as shown below
3- Clear the data label in the first transfer then transfer the script in the second one
Solution - K2 Cloud:
The problem in K2 Cloud is that the task form is displayed within the workspace using different URL than the parent page (Workspace) and here the script will not work because of the security mechanism Same-origin policy .
There are two URLs configured for K2 Cloud
1- Vanity
2- KUID
If you use the environment library to configure your user tasks URL in the Workflow or select the from by using the browse option then the IFrame source will be https:// KUID].onk2.com/runtime/runtime/form/uFormName]..
and this will not be the same origin as the parent page i.e. https://VanityExample.onK2.com/Workspace
In this case, don't use the environment library fields (SmartForms Runtime SSL) to construct custom URLs or the SmartForms option for tasks.
If you have more than one Cloud Instance, I would recommend storing your environments URLs in a SmartBox to avoid using static URL in your user tasks. then you can load the correct URL from the SmartBox and construct custom URL for the Workflow tasks
Example:
Environment URLs stored like this
Task Configuration:
Filter the results as below:
I am loading the Vanity URL from the SmartBox and filtering the results by the server URL which is the same as the workspace URL that is stored in the environment fields
Now you can implement the same steps mentioned above in K2 Five Solution to trigger the refresh function successfully.
HTH