How To Debug Canvas Apps Formulas in the Microsoft Power Platform

Blog post graphic with a maroon header reading "NEW BLOG POST." The title in large red font reads: "Controlling Spam in Dynamics 365 with Copilot AI." At the bottom left is a headshot of Brian Kretchman, labeled Senior Consultant, wearing a blue shirt and smiling. The New Dynamic logo with the tagline “Listen. Deliver” is on the lower right. The background is white with maroon accents.

Table of Contents

There are few products within the Microsoft Power Platform lineup that are as flexible (or as frustrating) as Canvas Apps. While Canvas Apps allow you to create almost any interface or navigation path you could possibly want, they can also come with some of the most vague and unhelpful errors imaginable. We would like to kick off a series discussing how to debug such issues within Canvas Apps, beginning with fixing formula errors of an app.

Something that we frequently use formulas for is the visibility of controls or the conditional formatting of text within Canvas Apps. Depending on how many conditions you may want to use as a criterion for this logic, these formulas can become complicated very quickly. Additionally, the normal interface can leave a bit to be desired when it comes to readability. Take the following screenshot as an example:

A computer screen displays a Canvas Apps code editor with a highlighted line of code at the top, a form field labeled Late fee lump sum payment, a validation error message in red, and a code output or debug pane on the right.
In this image, the formula above is formatting the text in red within the canvas to either be “Please choose a value over $99.99” if a value under a $100 is entered, “Please enter a value for lump sum payment #1” if a date is entered with no currency value, or to show no text if both of those tests are valid. But what if we had made a mistake in the formula, like forgetting one of the close parentheses?
A cropped screenshot of an error message in a code editor for Canvas Apps, highlighting “Invalid number of arguments: received 0, expected 1 or more.” and “Invalid number of arguments: received 1, expected 1.”.

If you have not done a lot of Canvas Apps, an error like “Invalid number of arguments” probably does not immediately read like something that says “you forgot to close a parentheses”, does it? Furthermore, clicking into the “View Problems” link does not direct you to where the issue actually is. So, how do we debug this?

First, take a close look at your formula for things like missing parenthesis or commas. Clicking on a parenthesis in the formula bar can help with this process since the formula bar will highlight its matched pair within the formula. In this case, we can see that the Is Blank function that is checking the value of txt_LumpSum1Payment is not being closed off where it should be, so adding a parenthesis will resolve the issue. See below.

Picture3nd
When it comes to missing commas, Canvas Apps’ function bar has built in IntelliSense to show what arguments each formula takes. While this will not explicitly tell you where a comma is missing, it can be used to see if too many or too few arguments are present in a formula. IntelliSense is triggered when a formula is first written out and each time a comma is added to a formula. If you need to quickly check the IntelliSense for a formula, try removing and readding a comma from a formula.
A screenshot of code in an editor with a tooltip, showcasing a conditional statement in Canvas Apps. Highlighted text displays function arguments, while the options bar and part of the code are visible at the top and bottom.

Something to get into the habit of doing is using the “Format Text” button at the bottom of the formula bar. While writing formulas in this manner does convert your text, it also takes up a more space on the screen. This will make spotting errors significantly easier than it is with potentially several nested formulas crammed together into one or two lines of text.

For the most part, issues with formulas come down to missing elements from a formula such as commas and parentheses. While there are tools to help debug these issues, like IntelliSense and highlights for parentheses, it is not always obvious how they can be used. Hopefully you found this article useful and we look forward to our next one about Monitor and Canvas Apps.

Working with New Dynamic

New Dynamic is a Microsoft Solutions Partner focused on the Dynamics 365 Customer Engagement and Power Platforms. Our team of dedicated professionals strives to provide first-class experiences incorporating integrity, teamwork, and a relentless commitment to our client’s success.   Contact Us today to transform your sales productivity and customer buying experiences. 

Join the Community

If you found this blog helpful, subscribe below to receive our monthly updates.

Join the Community

If you found this blog helpful, subscribe to receive our monthly updates.

Table of Contents

Share with your network

What our Customers Say