Alphabetical sorting of two array variables with content from document library columns in SPO with Azure Logic Apps

Cem 110 Reputation points
2023-11-30T21:46:44.39+00:00

I have a document library with two person columns (userA, userB) in SharePoint Online (SPO). For my Logic App workflow I need an alphabetical sorted output of the selected user names from the two person columns in two different emails. See below for more details.

In my Logic App workflow I fetch the display names of the two person columns with for each and append it to two arrays. Then I use the expression join () in the email send action. There are two types of email bodys:

  • first email body (user1 and user 2): each array in seperate lines
usersA: @{join(variables('userA'),'; ')}
usersB: @{join(variables('userB'),'; ')}
  • second email body (users): both arrays in one single line
users: @{join(variables('userA'),'; ')}; @{join(variables('userB'),'; ')}

This works good so far, but the conent is not sorted and I want to sort it ascending by the last name of the person. With every workflow run I get a different mixed output of display names. I tried it with the expression sort (), but I got an error message of using string instead of array. But my variables are both initialized as arrays.

How can I best achieve this? I hope somebody can help me with the Logic App Workflow. Thanks in advance for any assistance.

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
{count} votes

Answer accepted by question author
  1. Sonny Gillissen 3,996 Reputation points Volunteer Moderator
    2023-12-05T13:56:15.6033333+00:00

    Hi Cem,

    Thank you for reaching out on Microsoft Q&A!

    You use join(), but this joins all items in an array as a string with a delimiter. To join two arrays together you need to use union():

    union(variables('userA'),variables('userB'))

    With the joined arrays you can now use the sort() function to sort them properly:

    sort(union(variables('userA'),variables('userB')))

    With the result you can use the join() again to make a string of your combined and sorted array:

    join(sort(union(variables('userA'),variables('userB')),item()),'; ')

    Please click “Accept answer” if you find this helpful. Feel free to drop additional queries in the comments below!

    Kind regards,

    Sonny


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.