Advanced Canvas App Gotchas

I was recently working on a Canvas App tied to a Dataverse backend with some “more than out of the box” issues with PowerApps. These are issues where I had to spend some extra time figuring out the issue; the actual resolution was much easier (although extra steps), and this is where having a big red banner that says “You can’t do this” would be a boon to developers everywhere.

Setting Status Codes

I know, I know, Status and State Codes get set differently in PowerApps – but it’s been forever – isn’t it time we fixed that model and included it as part of a simple update, making it symbiotic with the rest of the ecosystem?

All that to say, if you have an entity that you want to update your status on, the best option I could find is to do a post “Patch” to your record, to another field, and then have a PowerAutomate flow kick off behind the scenes to update it accordingly. Solid as a rock, but I wish it didn’t take 2 steps.

Patch(
    Tasks,
    SelectedItem, 
    {
        MarkAsComplete: CanvasSetState.Completed,
        'Actual End': Now()
    }
);

For me, I created a hidden option set that, when updated, triggers our backend flow. I did try doing the statecode: OptionSet(1) a few times, and nothing worked. If you’re unfamiliar with PowerApps Canvas Apps, the above says – “Patch the Tasks table, with the selected item (a built-in construct which is great), with these fields.

Love the simplicity, wish it supported states.

Polymorphic Handling

As you can see from the above, I’m dealing with the Tasks entity, which therefore means I am using Polymorphic fields for our Regarding entity. These fields have been around for a very, very long time.

And yet when using them, it feels like the first time.

Filtering Polymorphic fields

Like any view, I wanted to allow users to filter the data they see on their screen. To do this with a Polymorphic field is a bit of a challenge, as these fields support access to multiple entities. To enable this functionality, you need to identify the entity you are filtering on and the field itself.

Sort(
        Filter(
                    Tasks,
                    IsType(Regarding, [@Projects]), 
                    AsType(Regarding, [@Projects]).'Project Reference' =  varSelectedProject.'Project Reference'
                ),
    'Created On',
    "Descending"
)

For bonus, I added the Sort, which wraps around our Filter. In the above code, you have to specifically declare the type you are filtering on and then the related field.

Submitting a Polymorphic Field

In my use case, I’m going from Project to creating a task, so I know the project ahead of time; I don’t need to provide a lookup for someone to find it. I checked, and many times my variable (varSelectedProject) had the value coming over, but whenever I called SubmitForm, it would not get submitted.

The solution is that once you submit your form, you get access to an object called “LastSubmit” which is very nicely named, that you then update with your Regarding field, pointed to your variable.

SubmitForm(EditTaskForm);
Patch(
    Tasks,
    EditTaskForm.LastSubmit,
    {
        Regarding: varSelectedProject
    }
);

Again, very simple now that I know, but getting there was a lot of back and forth.

Launch a Teams Channel

Not so much a gotcha, but I just thought this was a great, embedded add-on where you could call “Launch” and supply the URL to your Teams Channel (go to your Teams Channel and click – “Copylink”) and then be able to redirect right to that channel from wherever you are running the app.

Launch("https://teams.microsoft.com/l/channel/#ID#thread.tacv2/Office%20Channel?groupId=#ID#&tenantId=#ID#") 

More information on Launch is available here.

Also, shout out to the ease of use of integrating your Camera and photos with your image fields in the Dataverse. I thought this would be some kind of complex binary mapping, as can happen in Power Automate, but it’s not.

It would be great if our older sets of functionality (i.e., status codes and polymorphic fields) could be as simple as new features (integrating with other systems and hardware).

And as you can see, I don’t have to write as much code, but yes, all the hard stuff, required code.