Hi,
I'm working on a Flow that fetches JSON from an API. the schema has a couple of properties where the returned data can be a string, an array of strings or null (missing entirely).
The snippet of the schema looks like this
"name": { "anyOf" : [
{
"type": "string"
},
{
"type": "array"
},
{
"type": "null"
}
]
},
....
I'd like to be able to have the data in a single string for onwards use, and have used the join function when an array is returned OK, but it fails when a string is returned.
Is it possible to tell what the returned type of a property is so I can select the right method to handle it? I've read around it quite a bit but am stuck.
Solved! Go to Solution.
Hi @dht6000 ,
As far as I know, there is no easy out-of-the-box way to differentiate between an array or string.
You could use the following work around:
1. Initialize a string variable for the result, that saves the result of the API request.
1. Create a scope action.
2. Within the scope, set the string variable, assuming that you will receive an array. Note: you cannot initialize the variable within the scope.
3. After the scope, initialize a second string variable, when the scope fails (run-after). This variable saves the result of the scope.
Now you have two options:
1. The scope succeeds and you've got the result in your first string variable.
2. The scope fails. It's likely, your result was not an array, but a string or null. You can check with the result in the string variable.
The result if the scope, because it was given a string, looks like this:
Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '9893': 'The template language function 'join' expects its first parameter to be an array. The provided value is of type 'String'. Please see https://aka.ms/logicexpressions#join for usage details.'
I hoped this helps.
Regards,
Leo
----------------------------------------------
If my answer solved your issue, please mark it as complete.
If what I wrote helped you, please give it a thumbs up.
Hi @dht6000 ,
As far as I know, there is no easy out-of-the-box way to differentiate between an array or string.
You could use the following work around:
1. Initialize a string variable for the result, that saves the result of the API request.
1. Create a scope action.
2. Within the scope, set the string variable, assuming that you will receive an array. Note: you cannot initialize the variable within the scope.
3. After the scope, initialize a second string variable, when the scope fails (run-after). This variable saves the result of the scope.
Now you have two options:
1. The scope succeeds and you've got the result in your first string variable.
2. The scope fails. It's likely, your result was not an array, but a string or null. You can check with the result in the string variable.
The result if the scope, because it was given a string, looks like this:
Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '9893': 'The template language function 'join' expects its first parameter to be an array. The provided value is of type 'String'. Please see https://aka.ms/logicexpressions#join for usage details.'
I hoped this helps.
Regards,
Leo
----------------------------------------------
If my answer solved your issue, please mark it as complete.
If what I wrote helped you, please give it a thumbs up.
Thanks @leo85 that worked a treat. I ended up not using the second string but feeding the Scope output straight to a Condition to check for Failed or Aborted in the status, if that is true then I just set my String variable equal to the JSON output.
I found that in this article https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-control-flow-run-steps-group-scopes
Thanks again!
Dave
The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.
Learn to digitize and optimize business processes and connect all your applications to share data in real time.
User | Count |
---|---|
61 | |
54 | |
29 | |
27 | |
24 |