cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

workflow with http request

henk_stobbe
DynaMight Leader
DynaMight Leader

Good morning,

As shown below, it would be nice to use variables in the http request:

henk_stobbe_0-1718694577183.png

So my questions is this possible, or do I need to write my own fetch request?

  And I assume you need multiple returns for multiple variables or is the proper way state or document? 

In short what is the proper way for this?

KR Henk

 

 

 

 

 

 

3 REPLIES 3

ChristopherHejl
Dynatrace Advisor
Dynatrace Advisor

You can use the expressions documented at https://docs.dynatrace.com/docs/platform-modules/automations/workflows/reference as well as any default jinja2 function (link in the doc).
We currently do not support defining a fixed set of variables on the workflow to use anywhere (although on the roadmap for this year with the proper introduction of workflow input support and default values in the UI).
For now, if you want to manage a set of variables in one place to use throughout the workflow, your best bet would be an ad-hoc javascript task that returns the desired data.

Return data can be any json object, so complex, nested objects with any json supported types are possible. for example:

export default async function ({ execution_id }) {

  return {
    my_string: "Some important string",
    my_number: 42,
    my_list: [1,2,"something else"],
    my_object: {
      my_key: "my value",
      my_other_number: 196,
      my_boolean: true
    }
  };
  
}

will return as shown

ChristopherHejl_0-1718697341607.png

 

Then you can access the data using the result expression

{{ result("my_data_task")["my_object"]["my_key"] }}

ChristopherHejl_1-1718697398124.png

 

Note: in order to get proper autocomplete suggestion for the results, you'll need to update the sample result of your custom javascript task accordingly.
You can find that on the Sample Result tab

ChristopherHejl_2-1718697460304.png

Then Edit and update the content.

ChristopherHejl_3-1718697505708.png

Best way to do this I suggest to run the workflow once first, check the task works as expected and then use the "Sample from task exeuction" button which automatically updates the sample result with the result from the last execution:

ChristopherHejl_4-1718697563975.png

 


-----
Once we add full workflow input (and output) support, you will have a setting in the worklfow do define worklow scoped variables.

Great lesson thanks! (-;

Thanks for the question!

Featured Posts