<p>I created a <code>WorkflowTemplate</code> in which I want to pass result of a script template as an input parameter to another task</p>
<p>Here is my <code>WorkflowTemplate</code></p>
<pre><code>apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: dag-wft
spec:
  entrypoint: whalesay
  templates:
  - name: whalesay
    inputs:
      parameters:
        - name: message
          default: '[&quot;tests/hello&quot;, &quot;templates/hello&quot;, &quot;manifests/hello&quot;]'
    dag:
      tasks:
        - name: prepare-lst
          template: prepare-list-script
          arguments:
            parameters:
              - name: message
                value: &quot;{{inputs.parameters.message}}&quot;

        - name: templates
          depends: prepare-lst
          templateRef:
            name: final-dag-wft
            template: whalesay-final
          arguments:
            parameters:
            - name: fnl_message
              value: &quot;{{item}}&quot;
          withParam: &quot;{{tasks.prepare-lst.outputs.parameters.templates_lst}}&quot;

        - name: manifests
          depends: prepare-lst &amp;&amp; (templates.Succeeded || templates.Skipped)
          templateRef:
            name: final-dag-wft
            template: whalesay-final
          arguments:
            parameters:
            - name: fnl_message
              value: &quot;{{item}}&quot;
          withParam: &quot;{{tasks.prepare-lst.outputs.parameters.manifests_lst}}&quot;

  - name: prepare-list-script
    inputs:
      parameters:
        - name: message
    script:
      image: python
      command: [python]
      source: |
        manifests_lst = []
        # templates list preparation
        templates_lst = ['templates/' for template in &quot;{{inputs.parameters.message}}&quot; if 'templates/' in template]
        
        print(templates_lst)

        # manifests list preparation
        for i in &quot;{{inputs.parameters.message}}&quot;:
          if 'templates/' not in i:
            manifests_lst.append(i)

        print(manifests_lst)

    outputs:
      parameters:
        - name: templates_lst
        - name: manifests_lst
</code></pre>
<p>In the above script template I've added print statement of two variables <code>templates_lst</code> and <code>manifests_lst</code>. I want to pass these two variables result as in input to two other tasks in the dag. The two other tasks are <code>templates</code> and <code>manifests</code></p>
<p>The way I am accessing the output values is <code>&quot;{{tasks.prepare-lst.outputs.parameters.templates_lst}}&quot;</code> and <code>&quot;{{tasks.prepare-lst.outputs.parameters.manifests_lst}}&quot;</code>. It is not working</p>
<p>How we can I do this?</p>

Biru
<p><strong>1. Fully define your output parameters</strong></p>
<p>Your output parameter spec is incomplete. You need to specify <em>where</em> the output parameter comes from.</p>
<p>Since you have multiple output parameters, you can't just use standard out (<code>{{tasks.prepare-lst.outputs.parameters.result}}</code>). You have to write two files and derive an output parameter from each.</p>
<p><strong>2. Load the JSON array so it's iterable</strong></p>
<p>If you iterate over the string representation of the array, you'll just get one character at a time.</p>
<p><strong>3. Use an environment variable to pass input to Python</strong></p>
<p>Although it's not strictly necessary, I consider it best practice. If a malicious actor had the ability to set the <code>message</code> parameter, they could inject Python into your workflow. Pass the parameter as an environment variable so the string remains a string.</p>
<p><strong>Changes:</strong></p>
<pre><code>   - name: prepare-list-script
     inputs:
       parameters:
         - name: message
     script:
       image: python
       command: [python]
+      env:
+      - name: MESSAGE
+        value: &quot;{{inputs.parameters.message}}&quot;
       source: |
+        import json
+        import os
+        message = json.loads(os.environ[&quot;MESSAGE&quot;])
         manifests_lst = []
         # templates list preparation
-        templates_lst = ['templates/' for template in &quot;{{inputs.parameters.message}}&quot; if 'templates/' in template]
+        templates_lst = ['templates/' for template in message if 'templates/' in template]
         
-        print(templates_lst)
+        with open('/mnt/out/templates_lst.txt', 'w') as outfile:
+          outfile.write(str(json.dumps(templates_lst)))
 
         # manifests list preparation
         for i in &quot;{{inputs.parameters.message}}&quot;:
           if 'templates/' not in i:
             manifests_lst.append(i)
 
-        print(manifests_lst)
+        with open('/mnt/out/manifests_lst.txt', 'w') as outfile:
+          outfile.write(str(json.dumps(manifests_lst)))
+      volumeMounts:
+      - name: out
+        mountPath: /mnt/out
+    volumes:
+    - name: out
+      emptyDir: { }
 
     outputs:
       parameters:
         - name: templates_lst
+          valueFrom:
+            path: /mnt/out/templates_lst.txt
         - name: manifests_lst
+          valueFrom:
+            path: /mnt/out/manifests_lst.txt

</code></pre>
