So I am trying to check for array null values inside a loop but I don't really know the right format for that
Array example:
[
'value 1',
'value 2',
'',
'value 4',
]
this is the expression that I tried to write:
if(empty(outputs('splitTD')[variables('FirstRecord')]), replace(outputs('splitTD')[variables('FirstRecord')], '', 'Not specified' ), outputs('splitTD')[variables('FirstRecord')])
CodePudding user response:
You won't be able to use an inline expression with an entire array. I tried to convert the array to a string and use a replace
expression but it just didn't want to be converted back to an array.
You need to loop over it and do the processing that way. Also, if you want to make sure the array stays in its original order, you need to turn concurrency to 1, otherwise, it will run in parallel and invoke race condition style outcomes to the updated array.
The component within the loop is the IF statement, it will determine what to do with each item.
if(or(equals(item(),null), equals(item(), '')), 'Not specified', item())
Load this into your tenant to see a working version.
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"For_Each_Array_Item": {
"actions": {
"Append_To_Updated_Array": {
"inputs": {
"name": "Updated Array",
"value": "@if(or(equals(item(),null), equals(item(), '')), 'Not specified', item())"
},
"runAfter": {},
"type": "AppendToArrayVariable"
}
},
"foreach": "@variables('Array')",
"runAfter": {
"Initialize_Updated_Array": [
"Succeeded"
]
},
"runtimeConfiguration": {
"concurrency": {
"repetitions": 1
}
},
"type": "Foreach"
},
"Initialize_Array": {
"inputs": {
"variables": [
{
"name": "Array",
"type": "array",
"value": [
"value 1",
"value 2",
"",
"value 4"
]
}
]
},
"runAfter": {},
"type": "InitializeVariable"
},
"Initialize_Updated_Array": {
"inputs": {
"variables": [
{
"name": "Updated Array",
"type": "array"
}
]
},
"runAfter": {
"Initialize_Array": [
"Succeeded"
]
},
"type": "InitializeVariable"
}
},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
"method": "GET",
"schema": {}
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
This is the end result (this compose statement doesn't exist in the JSON above but you don't need) ...
CodePudding user response:
I have reproduced in my environment and got expected results as below:
Firstly, I have initialized array with your given input and then again initialized another empty array and then, I have used condition if(empty(item()),'No Element',item())
in for each loop and got results and followed below process:
The in compose variable as below:
Output: