So, I found a video on YouTube leading me in some direction to make it work. Not sure if it is the most optimal solution but this is what I did:
I have used a Select activity on the Jobs array variable and under the Map I have switched to Text mode and added the following expression:
concat('"', item()?['Key'], '":', item())
This outputs:
[
"\"123\":{\"Key\":\"123\",\"Release\":{\"ProcessKey\":\"PK123\"}}",
"\"456\":{\"Key\":\"456\",\"Release\":{\"ProcessKey\":\"PK456\"}}",
"\"789\":{\"Key\":\"789\",\"Release\":{\"ProcessKey\":\"PK789\"}}",
"\"987\":{\"Key\":\"987\",\"Release\":{\"ProcessKey\":\"PK987\"}}"
]
Then using a Compose action I convert the output from the previous action to a JSON object:
json(concat('{', join(body('Select_[jobs]'), ','), '}'))
This returns:
{
"123": {
"Key": "123",
"Release": {
"ProcessKey": "PK123"
}
},
"456": {
"Key": "456",
"Release": {
"ProcessKey": "PK456"
}
},
"789": {
"Key": "789",
"Release": {
"ProcessKey": "PK789"
}
},
"987": {
"Key": "987",
"Release": {
"ProcessKey": "PK987"
}
}
}
Finally, I am using another Select activity but this time on the Queue Items array where I use the normal mapping function to select the items from the queue items array that I need. Then to map the ExecutorJobKey in the queue items array with the Key in the jobs array I have declared a key name (in my case ProcessId) and in the value field I have added the following expression:
outputs('Compose_[jobsJSON]')?[item()?['ExecutorJobKey']]?['Release']?['ProcessKey']
The ProcessKey from the jobs array will now be added to the output of the Select activity and seems to be working faster than using a For Each loop.