04 Jan 2024 12:37 AM - edited 04 Jan 2024 12:37 AM
I am building two Worflows and one workflow calls an API Endpoint and fetches a value and Stores in a variable.
I am able to reference this return value between tasks within the same workflow by {{ result("task_name") }}.
However I need to use this variable returned by the first workflow to be used as a value in a POST request task in a second Workflow.
The question is, what is the syntaxt to reference return variables between workflows?
04 Jan 2024 06:26 AM
Hi @echwallah ,
You'll need to write the javascript code to access the result from that. You can find some example code on how to get to an execution details at https://docs.dynatrace.com/docs/platform-modules/automations/workflows/reference#task-result.
I would guess you'll first need to use the getActionExecutions to list the previous executions of the other workflow.
Gil.
04 Jan 2024 06:42 AM
Thanks @gilgi but the documentation shared which I have perused still is uses a syntax to access the variable within the same WorkFlow from preceding tasks to be used in the next action.
What I need is, is there a same reference to access a return variable from one workflow to be used as an argument in a different workflow?
Please provide details on the getActionExecutions to achieve this, if at all is possible. Is there no syntax like
{{ result(Workflow_name.("task_name") }}. This would make things very neat and easier.
04 Jan 2024 07:00 AM
The syntax you're showing here is only to be run within the same workflow as you've said. In order to access tasks from another workflow you'll need to add a javascript code task to your workflolw and in there access the data.
While I haven't done this before, I would think that you'll need to first to use the workflow client in order to retrieve the other workflow details (see https://developer.dynatrace.com/reference/sdks/client-automation/#getworkflow).
Based on that, I would assume that in the returned workflow result you find the information about the id of the last execution in the lastExecution Field and using this information you could then go ahead and run the getExecution or getTaskExecutions using the executionsClient.
Sorry I didn't provide any code but if I'll have the time I'll try later. Anyway - these instructions should lead you to achiev your desired goal.
Gil
04 Jan 2024 07:09 AM
Thanks @gilgi let me know if you can be able to have sample code to achieve this.
My thinking is that it would be simpler and easier to just reference the variable using a syntax like
{{ result(Workflow_name.("task_name") }} without writing too much code. I am not seeing the essence of a lot of code to achieve something simple like this and the Workflows are literally running in the same environment
What would be your opinion on this as an Enhancement or Product Idea?