The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ Power Apps

In this Power Apps Dataverse Tutorial, I will show you how to fix an error, The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ that comes while working with the Power Apps JSON function.

When I was working with Power Apps recently, I had to use the JSON function to get the names of the columns in the dataverse table.

I got a polymorphic error when attempting to use the Power Apps JSON function.

The screenshot below represents the error that displays: The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’.

The JSON function cannot serialize tables objects with a nested property called '_ownerid_value' of type 'Polymorphic'
The JSON function cannot serialize tables objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’

Now we’ll go into more detail regarding this issue and how to resolve it.

Also, Read: How to get Collection Column Names in Power Apps [From 3 Different Datasources]

The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ – Error

  • Here, I have a Dataverse Table named Car Booking Details. This table has various columns and as well as records as shown below.
  • Car Name, Booking Date, Buyer Name, and Buyer Contact Number are my Dataverse table columns.
Power Apps Dataverse table
Power Apps Dataverse table
  • Now I wanted to retrieve all the Dataverse table columns in Power Apps. In order to fulfill this requirement, I first established a Power Apps Collection and added all the Dataverse columns to it. [All the below codes I have written on the Button’s OnSelect property]
ClearCollect(
    colCarBookingInfo,
    'Car Booking Details'
);

Where,

  1. colCarBookingInfo = Collection name
  2. Car Booking Details‘ = Dataverse table name
  • I then used the code below, where I had to use the Power Apps JSON function, to extract all of the collection column headings.
Set(
    varColumnNames,
    Distinct(
        Ungroup(
            MatchAll(
                JSON(
                    colCarBookingInfo,
                    JSONFormat.IgnoreBinaryData
                ),
                "([^""]+?)""\s*:"
            ).SubMatches,
            "SubMatches"
        ),
        Value
    )
)

Where,

  1. varColumnNames = Variable name where the result will store
  2. colCarBookingInfo = Collection name that you have created
  • While I used the JSON function and added the collection name to it, I got an error like “The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’.
  • The error states clearly that lookup fields like ownerid and primarycontactid cannot be serialized. There is a JSON format value to include Unsupported types, therefore it’s all ok. But how do you define it? We have previously specified IgnoreBinaryData, after all.
The JSON function cannot serialize table / object with a nested property in Power Apps
The JSON function cannot serialize table / object with a nested property in Power Apps

In the below section, we will see how we can fix this above issue in Power Apps JSON function.

The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ – Solution

When I ran across this issue, I did some online research and visited a number of websites. However, I came up with a solution and added it to the code. I then resolved my problem and continued the process as needed.

It’s a simple trick, though. To combine the two formats, all you need to do is use the “&” operator; in fact, you can use as many as you like. And also, you need to use the JSONFormat.IgnoreUnsupportedTypes function.

The JSON function cannot serialize tables / objects with a nested property called '_ownerid_value' of type 'Polymorphic'
The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’

Refer to the solution code below as well:

Set(
    varColumnNames,
    Distinct(
        Ungroup(
            MatchAll(
                JSON(
                    colCarBookingInfo,
                    JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes
                ),
                "([^""]+?)""\s*:"
            ).SubMatches,
            "SubMatches"
        ),
        Value
    )
)

Where,

JSONFormat.IgnoreUnsupportedTypes = Unsupported data types are accepted, but they won’t be included in the final result.

Simply Save, Publish, and Test the app after entering the above formula. And now it functions wonderfully.

This is how we can solve the Power Apps JSON function error i.e. The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’.

Furthermore, you may like some more Power Apps & Dataverse tutorials:

In this Power Apps Dataverse Tutorial, We discussed how to solve the error, The JSON function cannot serialize tables / objects with a nested property called ‘_ownerid_value’ of type ‘Polymorphic’ that comes while working with the Power Apps JSON function.

>