0

I am writing a Power automate flow to process data from a Sharepoint repository which contains managed metadata fields (columns) with zero or more terms each to generate a list where each row has only one term label. From:

id term
1 (none)
2 term1, term2

to:

id_original term
1 (none)
2 term1
2 term2

I need only the labels of each managed term so I use "Select" to generate an array with only the labels:

{
    "inputs": {
        "from": "@items('Apply_to_each')?['Type_x0020_of_x0020_material']",
        "select": "@item()?['Label']"
    },
    "metadata": {
        "operationMetadataId": "xxx"
    }
}

The input data is:

[
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedTaxonomy",
    "TermGuid": "xxx",
    "WssId": 38,
    "Label": "Reading material, article",
    "Path": null,
    "Value": "Reading material, article|xxx"
  },
  {
    "@odata.type": "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedTaxonomy",
    "TermGuid": "xxx",
    "WssId": 91,
    "Label": "Other",
    "Path": null,
    "Value": "Other|xxx"
  }
]

The output I get is (seems to be?) an array:

[
  "Reading material, article",
  "Other"
]

Since I need later to iterate on the list of items and I cannot have empty lists, if the list is empty I used a "Compose" to return a list with only one empty item, otherwise I return the output as is:

if(equals(length(outputs('Select_TyMa')), 0), createarray(' '), outputs('Select_TyMa'))

However I get an error:

Unable to process template language expressions in action 'Compose' inputs at line '0' and column '0': 'The template language function 'length' expects its parameter to be an array or a string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#length for usage details.'.

I searched online but I don't understand what is wrong with my approach. How can I make the last "Compose" work as I described?

2
  • Try using this expression: if(equals(outputs('Select_TyMa'), null), createarray(' '), outputs('Select_TyMa')). Let me know if it works. Commented Feb 2, 2023 at 5:56
  • I was wrong about the "The output I get is (seems to be?) an array", in fact it was an array inside an object "body".
    – FarO
    Commented Feb 2, 2023 at 9:09

1 Answer 1

1

Contrary to what I thought from looking at the output window when testing the flow, once I checked the raw output I noticed that the array was wrapped inside a "body" object.

I solved by changing outputs('Select_TyMa') to outputs('Select_TyMa')?['body'].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.