on 2021 Mar 15 8:32 AM
Dear all,
I am currently using workflow APIs to instantiate an approval workflow from my (CAP) App. this works absolutely fine. Afterwards I am now receiving back the context of that workflow instance and read the status(decision) from the context for that workflow instance. this also works fine. Each of my Books has a workflow instance ID attached for which I am pulling the context back to my app via API Call. Please verify/check my code below.
the console.log(book) in thend then shows the right value "approved" for the field status_workflow but it is not written into the database and the UI. Do you see any reason why it is like that? it looks like due to the await statement the logic gets influenced as the first statement book.status_workflow = "pending" writes the status correctly into the database and UI but afterwards this does not happen any more.
srv.after('READ', 'Books', async (books,req) => {
console.log("I am in the READ Event handler");
const workflowService = await cds.connect.to('workflowDestination');
const tx = cds.transaction(req)
books.filter(book => book.workflow_id != null) .forEach (async book => {
book.status_workflow = "pending";
const workflow_context = await workflowService.tx(book)
.get(`/v1/workflow-instances/${book.workflow_id}/context`)
book.status_workflow = workflow_context.decision;
console.log(book)
})
})
I would much appreciate any feedback!
Best Regards
Max
Request clarification before answering.
Hi Max,
the `forEach` loop ignores the Promises returned, which might have been the problem.
For the other question, let's handle it in the place you linked.
Please close this one if you're satisfied so far.
Thanks and regards,
Tim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
gregorw That wasn't my intention – thanks for the hint! Fixed the link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you guys!
issue could be solved by changing the forEach to a regular for loop. Never the less now I am working on the same functionality just via ServiceTask wich would be the proper way to do it as in that scenario the workflow app communicates the status back to the books app. In the first one the books app actively fetches the contexts from worklfow app. You can find a referring post here:
https://answers.sap.com/questions/13315407/sap-btp-cf-workflow-configure-service-task.html
Any thoughts and hints would be highly appreciated.
Best Regards
Max
Hello Max,
please refer to https://cap.cloud.sap/docs/guides/services#sending-requests on how to make a transaction to query data. I think you'd need `req` as argument to `workflowService.tx`.
By the way, it seems you are not using the `tx` defined in the fourth statement.
Hope that helps,
Tim
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Tim,
please make sure that you use external links in a public forum:
https://cap.cloud.sap/docs/guides/services#sending-requests
CU
Gregor
User | Count |
---|---|
87 | |
10 | |
9 | |
8 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.