1
votes

I have a workflow in Azure Logic App that execute an API call to get custom fields values from Trello card. Then, I put a 'for each' step to get the definition (field name) of every custom field. This is made by calling another method of Trello API. I want to create a JSON object based in the values I've got from these API calls. The format of JSON is as simple as:

{
"name1": "value1",
"name2": "value2",
...
}

Edit:

I have an initial object with this schema:

 {
  "Cel": "",
  "City": "",
  "CreatedOn": "",
  "Lead": "",
  "Mail": "",
  "Brand": "",
  "Name": "",
  "Salesperson": ""
}

It's a simple json object with key:value pairs.

I want to set the object properties inside a for each loop. I got the values of the fields from Trello API (returns an array like):

[{"id":"5fbdb5da1626b7499d690ebf","value":{"date":"2020-11-09T15:00:00.000Z"},"idCustomField":"5fbdb5cee93a775e4a9405e5","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946e31680220774095ed9","idValue":"5fa9464bd260145aacba03ed","idCustomField":"5fa9462327f2c331a184a483","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946e0dafc5b7ead25411a","value":{"text":"Lilia Noemi Cabral"},"idCustomField":"5fa9454303ee497b7b99772a","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946bf8697d18d58b73ac1","value":{"text":"Tania"},"idCustomField":"5fa94518f410418c57662fd0","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946c3a2ee2771d26ba30e","value":{"text":"[email protected]"},"idCustomField":"5fa945088fc819708d157c5b","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946bc38b469081857ea9a","value":{"text":"Asuncion"},"idCustomField":"5fa944fe9d7af62b3806c8b6","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946b82bbaf938c4c3c341","value":{"number":"098234567"},"idCustomField":"5fa944e59527342399f460e2","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"},{"id":"5fa946b32aad4d323ba0648e","value":{"text":"Tania Cardozo Olivera"},"idCustomField":"5fa944d779089c6ca5cf534b","idModel":"5fa53d647b35d5744fd8b856","modelType":"card"}]

I put a for each step to iterate and parse the field value. I got the field name with another call to Trello API, which return this response:

{"id":"5fa94518f410418c57662fd0","idModel":"5f988b8cb225cc7ac34deae9","modelType":"board","fieldGroup":"53eb88d2e4cde013cb9f03e7500ad1a00a4c82f153f9165f7b1ec554f4cc2d74","display":{"cardFront":true},"name":"Name","pos":81920,"type":"text","limits":{"customFieldOptions":{"perField":{"status":"ok","disableAt":50,"warnAt":45}}},"isSuggestedField":false}

So, I matched the idCustomField to get the field name and field value. Now I want to set the property in the initial declared object (each property name is equal to custom field name in Trello)

I've tried using a compose step with:

setProperty(variables('Object'),body('Parse_JSON')?['name'],body('Parse_JSON2')?['text'])

And later set the variable object to the compose outputs, but doesn't work fine. The result object doesn't have all the properties set. My idea is to set all the object properties inside the for each loop.

What could I be doing wrong?

Is there a way to achieve that in Azure Logic Apps?

Thanks in advance!

1
Hi, I'm a little confused about your situation. Could you please provide a sample of your custom field format ? Or provide some screenshots of your current logic app ?Hury Shen
Thanks for your reply @HuryShen. I've edited the post to add more informationHugo Morillo
Ok, I will check your update requirement.Hury Shen
It seems a little complex of your description. I have two more things don't understand: 1. You didn't mention how to match idCustomField. 2. Not all of the items in the array has the field text, so what are you going to do with the items that don't have text field.Hury Shen
First, I make a Trello API call to get all the customFields (json array). The for each uses this array to iterate over single customField. In each iteration, I made the 2nd API call to get the definition of the custom field (using the idCustomField) and returns a json with the field name and other definitions. I've already resolve the items that don't have text field, using nested conditions (the fields may be text, date or number). I managed to get the field name and its value correctly in each iteration, but i'm facing the problem to set those values into the object propertiesHugo Morillo

1 Answers

0
votes

You should use

setProperty(variables('object'), body('Parse_JSON')?['name'], body('Parse_JSON_2')?['value']?['text'])

instead of

setProperty(variables('Object'),body('Parse_JSON')?['name'],body('Parse_JSON2')?['text'])

================================Update===================================

Your problem may be caused by the "For each" loop run in parallel, so please try with the steps below (Note: if you do this change, when you want to change back, sometimes it will show error message when you click "Save" of you logic app. So please create another logic app for test or make a backup copy of logic app):

Click the "Settings" of your "For each" loop. enter image description here Then enable Concurrency Control and set Degree of Parallelism as 1. enter image description here