web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error while sorting ar...
Power Automate
Answered

Error while sorting array of objects

(0) ShareShare
ReportReport
Posted on by 893 Super User 2026 Season 1
Hello,
 
Fairly certain I know what the problem is, but I can't figure out how to solve for it. In this flow I am obtaining data from two different API end points. After much filtering and data manipulation I am joining the data set results using a compose action union and then sorting on a common field. Unfortunately, after all the data manipulation the field that I am sorting on (Zone) is a string type from one data set but a number type in the other data set. Therefore, I get the error circled below on the compose sorting action.
 
How and where in the flow do I convert the Zone number type field to a string or, I suppose, the other Zone field to a number type?
 
I tried to change the schema in one of the Parse Json actions but that failed.
 
Hope that makes sense. Appreciate any suggestion. Thanks!
 
 
 
 
Categories:
I have the same question (0)
  • Suggested answer
    Artur Stepniak Profile Picture
    1,539 Moderator on at
    Hello,
     
    you'd need to save the value in the variable, convert it and recompose the JSON before the union. Something like this:
    {
      "test": variables('TestValue'),
      "best": outputs('Parse_JSON')?['body/best']
    }
    In case of any other questions, let me know. If the answer helped you, mark it, so that others can benefit from it.
     
    Best regards,
     
    Artur Stepniak
    Interested in GenAI? Visit my site!
  • Suggested answer
    mrcwojcik Profile Picture
    68 on at
    At beginning, when you start work with mentioned data, use Select action and map your fields to format you want.
    After that you will work on same and well prepared data
     
     
  • Cgangweg01 Profile Picture
    893 Super User 2026 Season 1 on at
    Hello @Artur Stepniak ,
     
    Thank you for the reply. I checked out your CoPilot/GenAI web site. Very informative. I'll be following!
     
    I don't quite get your suggested answer as I'm fairly new to this.
    Not sure where to put this or how to replace it with my data.
     
    {
      "test": variables('TestValue'),
      "best": outputs('Parse_JSON')?['body/best']
    }
     
    After the JSON is parsed, the select action that maps the following is done with the Zone value initially set equal to zero, see below. Later in the flow after some manipulation and a lookup I remap and insert an actual zone number, but it inserts as a string. See zone 'if expression' below in screen shot.
     
    Any suggestion now?
     
    Initial select mapping ...
        {
            "StoreNumber": 124,
            "StoreName": "test store",
            "Price": 2.22,
            "PriceType": "ZONE",
            "PriceStartDate": "2024-12-30T00:00:00",
            "PromotionType": "T",
            "PromotionalPrice": 2.22,
            "PromotionStartDate": "2024-12-30T00:00:00",
            "PromotionEndDate": "2025-01-31T00:00:00",
            "CouponNumber": "hold",
            "PriceStatus": "CUR",
            "Zone": 0,
            "PriceEndDate": "hold",
            "Quantity": "hold",
            "Excluded": "hold"
        }
     
     
    if(equals(length(xpath(xml(outputs('Compose_4')),concat('//data[LookUpStr=',item()?['StoreNumber'],']/Zone/text()'))),0),'',xpath(xml(outputs('Compose_4')),concat('//data[LookUpStr=',item()?['StoreNumber'],']/Zone/text()'))?[0])
     
     
    Thanks!
     
     
  • Suggested answer
    Cgangweg01 Profile Picture
    893 Super User 2026 Season 1 on at
     
    Hi!
     
    Solved!
     
    Thanks for leading me in a direction!
     
    I just added the int() function around my if statement in the select action to covert the Zone string into an integer type. Worked like a charm.
     
    int(if(equals(length(xpath(xml(outputs('Compose_4')),concat('//data[LookUpStr=',item()?['StoreNumber'],']/Zone/text()'))),0),'',xpath(xml(outputs('Compose_4')),concat('//data[LookUpStr=',item()?['StoreNumber'],']/Zone/text()'))?[0]))
     
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 276 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard