Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to populate a JSON structure with task & subtask fields

Deiser Service Team February 17, 2022

Hello!

I'm doing an automation that will call a REST endpoint with a JSON structure containing a 'header' with info from the task and one 'line' per subtask with info from the subtask.

Output should be something like this:

{
    "YTXTCAB": "{{issue.summary}}",
    "YWSCYLINSOL":
    [
        {
            "$uuid": "{{issue.subtasks.uuid}}",
            "YITMREF": "{{issue.subtasks.YITMREF}}",
            "YITMDES": "{{issue.subtasks.YITMDES}}",
            "YQTYPUU": "{{issue.subtasks.YQTYPUU}}",
            "YEXTRCPDAT": "{{issue.subtasks.YEXTRCPDATv}}",
            "YCCE3": "{{issue.subtasks.YCCE - Proyecto}}",
            "YTXTLIN": "{{issue.subtasks.descripcion}}"
        },
    ]

}

 

Where the inner structure is replicated for each subtask inside the array [].


The above example lines do not work, of course, as you get just one line in the array with an all the field values from all subtasks in each field. Like below:

 

{

  "YTXTCAB": "TEST - Sage",

  "YWSCYLINSOL":

  [

     {

       "$uuid": "123-abc, 456-def",

       "YITMREF": "YITMREF 1, YITMREF 2",

       "YITMDES": "YITMDES 2, YITMDES 2",

       "YQTYPUU": "1.0, 2.0",

       "YEXTRCPDAT": "2022-02-17, 2022-02-18",

       "YCCE3": "YCCE 1, YCCE 2",

       "YTXTLIN": ""

     },

  ]

}

 

How would you go about getting one line of the inner structure into the JSON for each subtask?

 

Thanks

Jorgen

1 answer

1 accepted

0 votes
Answer accepted
Deiser Service Team February 17, 2022

I have found the solution, pasting it below:

{
    "YTXTCAB": "{{issue.summary}}",
    "YWSCYLINSOL":
    [
       {{#issue.subtasks}}
       {
          "$uuid": "{{uuid}}",
          "YITMREF": "{{YITMREF - Código artículo}}",
          "YITMDES": "{{YITMDES}}",
          "YQTYPUU": "{{YQTYPUU - Cantidad a comprar}}",
          "YEXTRCPDAT": "{{YEXTRCPDAT - Fecha recepción prev}}",
          "YCCE3": "{{YCCE - Proyecto}}",
          "YTXTLIN": "{{description}}"
       }
       {{^last}},{{/}}
       {{/}}
    ]
}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events