Hi guys,
we have the requirement to start an Appian process via API from an external system and redirect the user to the url of the first task of that process. I tried to achieve this in the following way.
We created a process model and activity-chained the first user input task with the start node. Then we created a POST api and start the process with a!startProcess and we valued the onSuccess parameter of that rule like this:
a!httpResponse( statusCode: 200, headers: { a!httpHeader(name: "Content-Type", value: "application/json") }, body: a!toJson({ taskUrl: a!urlfortask( index(rule!LM_getTaskDetailsByPid( pid: index(index(fv!processInfo, "pp", null), "id", null) ), "taskId", null) ) }) )
where rule!LM_getTaskDetailsByPid is a rule that, given a process id, retrieves the id of the active task of the process in the taskId component using a task report and query analytics.
Unfortunately we noticed that sometimes this fails because the system tries to evaluate LM_getTaskDetailsByPid before the process has reached the user input task!
How could we achieve this in a safe way?
Thank you to anyone could help us!
Lorenzo
Discussion posts and replies are publicly visible
Hm ... Can you try to use a process report and queryProcessAnalytics instead of that plugin function?
Is this behaviour totally uncertain or is it for some conditional flow? Make sure that all the nodes between Start node and attended task are properly chained.
You need to confirm that the task is actually active by the time you are preparing response in API, for troubleshooting you can create another flow which will add some delay to a!startProcess() returning in API. Check if the task URL is getting generated everytime now?
Another possibility could be that the Task Report is not getting refresh instantly and queryProcessAnalytics is unable to get the taskId, you can try getactivetaskidsforprocess() function available in Task Management Smart Services plugin to get the taskId if that helps.
Hi Sanchit! I think you got it with your second attempt!!! getting the task id with getactivetaskidsforprocess() instead of using the process report seems to have solved my issue!!!! I will test it extensively, however. Anyway, thank you very much!!
Regarding the first possibility, I tried but the API doesn't wait for the timer to complete before responding.
Adding a time to that flow will immediately break the chain at the timer node. It will not add any delay to a!startProcess returning.
Yes apologies for that, I tried it myself in a Test API and and yes the chaining breaks.
Thanks for the correction/information.
Glad to hear that . Yes test it thoroughly.
Apologies for the first suggestion, I was wrong.