Tuesday, June 29, 2021

Bug in Teams Dataverse/PowerApps connector

Fortunately my level of trust with anything new on the Power Platform is near zero.  Everything must be tested before I will rely upon the most basic features available.  This caution paid off today in that I only wasted about 15 minutes before figuring out the problem.

I was getting the error: The function 'Patch' has some invalid arguments. The specified column X does not exist.  The column with the most similar name is X.

The issue?  You cannot (currently) Patch() a record from a Collection to Teams Dataverse (but you can to SharePoint, SQL, etc...)

Oddly enough, both work fine connecting to the standard Dataverse (non-Teams).

NOTE:  I have a "fix" from MS and will detail below

Here's the gist.  If you're the kind of person like I am and you prefer to build out your data structures before you write them out to your data source to make 100% that you are doing what you think you are, then you store the record you're planning to write out to said source in a Collection first.  

So while the following code would work fine if writing to SharePoint, it does not work using Teams Dataverse (as of 2021-06-29).

ClearCollect(
    itemToWrite,
    {displayName: "John"}
);
ClearCollect(
    itemWritten,
    Patch(
        myDataverseTable,
        Defaults(myDataverseTable),
        First(itemToWrite)
    )
)

What breaks here is the bolded line above: First(itemToWrite).  It throws the following error


Notice that little bit of humor there?  The column 'displayName' doesn't exist, but 'displayName' does.  Now, trying this w/ quotes around 'displayName' on the original ClearCollect() doesn't work either.  It just won't work.  So what's the column's right name?

That is not the problem.  The problem is somewhere in the Dataverse connnector in how it is converting a Collection() into the values to write out to the Table.  

How do I know this?  Because THIS works:

ClearCollect(
    itemWritten,
    Patch(
        myDataverseTable,
        Defaults(myDataverseTable),
        {displayName: "John"}
    )
)

That is the exact same value that we stored in a Collection before.  Which DID NOT work.

The "Fix"

I'm not sure completely how I feel about this one as it requires that I change the specifics on the Collection I'm going to write out based upon the ultimate data source it is going to.  So code that writes to SharePoint won't work if writing to Dataverse (and vice-versa).  But I do see why MS is trying to tackle a different problem actually CAUSED this issue.

Here's the fix for the original code above:

ClearCollect(
    itemToWrite,
    myDataverseTable@{displayName: "John"}
);
ClearCollect(
    itemWritten,
    Patch(
        myDataverseTable,
        Defaults(myDataverseTable),
        First(itemToWrite)
    )
)

If you've ever wrestled with some complex statements that are referencing values within multiple objects that are external to your PowerApp, then you know that MS needs to fix some ways in which we reference these values if we want to be explicit vs. "hoping" that the specific field name we're referencing actually belongs to the Object/Container that we imagine it does.

I really don't like that I have to force a reference to the Datasource I'll ultimately write to because that really forces us into a corner per how/when you build a Collection to write from.  However, as I almost always do this in the lines right before I write out to the Datasource, and this is only done w/ that as the purpose, I think this might be reasonably acceptable.

But I also now wonder what this might look like if I threw it into the JSON() function...

Final Thoughts

I just submitted this over to see how our corporate support paths handle this vs. the Microsoft public boards do.  We'll see if this gets more attention this way vs. me just posting online.
Microsoft did give me a fix, but I'll say that I'm not 100% satisfied w/ it currently.  We'll see how this plays out in my other use-cases.

For now, you can still bypass the problem by not assigning whatever you want to write to Dataverse to a Collection first.

No comments:

Post a Comment

Because some d-bag is throwing 'bot posts at my blog I've turned on full Moderation. If your comment doesn't show up immediately then that's why.

DIAF Visualpath team