Home > Forum > Rules, JS, SQL > Task Delegation Fails with 500 Error (Works in Swagger)

Task Delegation Fails with 500 Error (Works in Swagger)
0

Hi everyone,

I’m working on a feature, where single button triggers a set of actions that grants permissions across related parent and child workflows, and delegates active task to other user using REST API.
I'm currently facing a frustrating issue with the task delegation API using the endpoint POST /api/data/v6.0/db/{dbId}/elements/{elementId}/admin/tasks/assignment
When I use this endpoint via Swagger, the task delegation executes successfully. Here's a sample of the payload that works perfectly in Swagger:

{
"task": {
"userId": "xxx@gmail.com"
},
"delegatedTask": {
"userId": "yyy@gmail.com",
"description": "Changed by REST Web Service",
"sendEmail": false,
"emailMessage": ""
}
}

It returns 200 OK with the message Task was delegated.

When I try to execute the exact same request from a “Call REST Web Service” action within a button, I consistently get a 500 Internal Server Error with timeout details, even though curl is identical as the one from swagger.

Error log:
Public Api POST /api/data/v6.0/db/1/elements/61445/admin/tasks/assignment
Status code: 500 Error message: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
The statement has been terminated. Callstack: Microsoft.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

Anyone got an idea what could be causing this error?

EDIT1:
Interestingly, when I change the userId in the payload to a non-existent user, the response returns:
409 Conflict
{
"type": "ValidationError",
"description": "User zzz@gmail.com does not exist or no tasks were found for this user.",
"errorGuid": "d0bdb551-8432-48a9-b011-f7e9cf10fb85"
}
But when the userId is correct and points to the actual task owner, the same request results in a 500 Internal Server Error. So the request passes validation and is received, but something goes wrong deep in the backend logic

MVP

Hi Marcin, by any chance are there any other actions that happen in the same automation, and modify the same document ?
If so have you tried moving that REST action to the first place?

We've faced similar issues and order od operations seems to be important.

I'm thinking that internally when there is an action involving SQL on the same item(I'd) it starts a transaction and locks that row for modifications untill end of the automation.

So when a REST action tries to update that document there is a lock on db level which results in timeout, as that rest action would try to execute as new transaction, not the same one. Webcon sees it as two different actions, one is executed by automation, second is not correlated it's just started as separate bg task from API endpoint.

MVP
In reply to: Marcin Borowiec

Hi Maksymilian,
Please find the screenshots attached.

Okay, so everything is clear now,

When there is a path started, Webcon locks that specific document, so it can't be modified by other processes (which a REST call would be treated as) until path transaction ends.
This example just won't work, as you are trying update document, while it's already being processed (Dane żądania, URL, ID Elementu).

It's not possible and in this case it is a feature not a bug.

Is there any specific reason why you are trying to delegate task instead of just creating new one with Create Task Action*?
This would provide mostly same experience, although it won't be marked.

*https://docs.webcon.com/docs/2025R2/Studio/Action/TaskAssign/Action_TaskCreation

If for some reason delegation is necessary, then a dirty workaround could be some cyclic action (let's say every 15min, from 6 to 18), which would get all documents which should be processed with task delegation, and then using for-each operator to trigger REST requests.
This won't be done in context of the document so should work, as the document won't be involved in any processing (unless it will be, then rest admin mode, and forcecheckout parameters could come in handy).

MVP
In reply to: Marcin Borowiec

bump, anyone got any idea on how to fix it?

Hi,

this is really an interesting behavior.

While it is possible the below case is possible , this is not possible for the current workflow instance.
- Checkout workflow instance 1 / open in edit mode
- Execute REST action from workflow 2 to delegate a task of workflow 1
- Edit and save workflow 1
- Changes and delegated task is shown after saving workflow 1

I have to admit that I didn't come up with delegating task via the API. This is a lot easier than creating a path on each step to update the tasks. At least if the original task owner should still be assigned.. If this shouldn't be the case, then there's no way around than using paths.

While this is an interesting finding it doesn't help much.

If you want to stick to the delegation option, then I see only one reliable solution. Start a "technical delegation workflow", populate and item list with all the workflow instances which should be updated:
- Instance id
- Assigned to user
- Delegate to user
Add a timer to the step in which the workflow has been saved and this will then execute the delegation with a short delay. This would allow that the button execution is finished before the delegation has been executed. Even if the delegation would fail, the users could continue to work and you could create a task/mail to look at this technical workflow.

The only other alternative would be a path. If you don't want to show it as a path but as a button. You could hide the path with a form rule and add a hyperlink action to the button with:
javascript:MoveToNextStep({PH:355})


Best regards,
Daniel

MVP
In reply to: Daniel Krüger (Cosmo Consult)

Hi,

this is really an interesting behavior.

While it is possible the below case is possible , this is not possible for the current workflow instance.
- Checkout workflow instance 1 / open in edit mode
- Execute REST action from workflow 2 to delegate a task of workflow 1
- Edit and save workflow 1
- Changes and delegated task is shown after saving workflow 1

I have to admit that I didn't come up with delegating task via the API. This is a lot easier than creating a path on each step to update the tasks. At least if the original task owner should still be assigned.. If this shouldn't be the case, then there's no way around than using paths.

While this is an interesting finding it doesn't help much.

If you want to stick to the delegation option, then I see only one reliable solution. Start a "technical delegation workflow", populate and item list with all the workflow instances which should be updated:
- Instance id
- Assigned to user
- Delegate to user
Add a timer to the step in which the workflow has been saved and this will then execute the delegation with a short delay. This would allow that the button execution is finished before the delegation has been executed. Even if the delegation would fail, the users could continue to work and you could create a task/mail to look at this technical workflow.

The only other alternative would be a path. If you don't want to show it as a path but as a button. You could hide the path with a form rule and add a hyperlink action to the button with:
javascript:MoveToNextStep({PH:355})


Best regards,
Daniel

I just came back here to say, that this javascript:MoveToNextStep({PH:355}) in hyperlink action is genius, never thought about that one, don't have a use case, but whoa!