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 / Values disappearing af...
Power Automate
Answered

Values disappearing after Sort-Object

(0) ShareShare
ReportReport
Posted on by 52

I'm populating $dataTable this way:

# Use Invoke-WebRequest to send a GET request to the URL
try {
 $response = Invoke-WebRequest -Uri $url -Method Get -UseBasicParsing
 # Convert the JSON response to a PowerShell object
 $jsonData = $response.Content | ConvertFrom-Json

 # Create a DataTable to store the data
 $dataTable = New-Object System.Data.DataTable

 # Check if the JSON data is not empty and has elements
 if ($jsonData -and $jsonData.count -gt 0) {
 # Dynamically add columns based on the JSON object properties
 foreach ($property in $jsonData[0].PSObject.Properties.Name) {
 $col = New-Object System.Data.DataColumn $property, ([string])
 $dataTable.Columns.Add($col)
 }

 # Add rows to the DataTable
 foreach ($item in $jsonData) {
 $row = $dataTable.NewRow()
 foreach ($property in $jsonData[0].PSObject.Properties.Name) {
 $row[$property] = $item.$property
 }
 $dataTable.Rows.Add($row)
 }
 }

 I then attempt to sort them using the line below, but the columns "Truck", "DriverName", and "DeliveryDate" are empty in $sortedData, even though they are populated in $dataTable. See pics for example.

 

Sorting code:

$sortedData = $dataTable | Sort-Object WarehouseCode, Truck, DriverName, SalesOrderNo, LineNumber, DeliveryDate , pickstatus, picktime, pickcomplete_time, ItemCode, QuantityPicked, QuantityOrdered

 

sortedData.noVals.png
dataTable.hasVals.png
I have the same question (0)
  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,255 Moderator on at

    @user42 

     

    Could you please share some screenshot of your complete desktop flow and also explain how your datatable looks like in PAD before sorting? Share some screenshot on the same(I believe the attached screenshot are taken from different IDE and not in PAD).

  • Verified answer
    user42 Profile Picture
    52 on at

    Hi @Deenuji , thanks for getting back to me.

    You are correct, the pics from from PowerShell ISE debug view.

    I'll break down what's going on in more detail, with pics, below:

    • Environment before call that strips the data
      • PAD1.png
      • Default values initialized
    • PowerShell script runs
      • PAD2.png
      • %PowershellOutput% gets populated with the returned data, but the data is missing the values of th3 field.
        • The script is in script1.ps1
        • I piped the json that's returned from the web query to a text file and the values are there before the sort command.
        • After the sort command, the values of the 3 fields are blank in $sortedData, but they are actually in $dataTable, which is what I was showing in my original post.
        • The problem appears to be on line 35 in script1.ps1.

     

  • user42 Profile Picture
    52 on at

    @Deenuji I've figured out the issue, sadly it was a problem between the keyboard and the chair.

     

    Your request for more info helped me isolate the issue though, so thanks!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 796

#2
Valantis Profile Picture

Valantis 568

#3
Haque Profile Picture

Haque 538

Last 30 days Overall leaderboard