Skip to main content

A more powerful data platform for your canvas apps: introducing business rules in CDS

When you create a canvas app in PowerApps, you can now use server-side business logic from the Common Data Service.  For a canvas app, you start with your user experience, crafting a highly tailored interface with the power of a blank canvas and connecting it to the Common Data Service along with your choice of 200 data sources.

 

If you don't have an new environment (created after March 20th 2018) with the Common Data Service enabled, check out this blog to learn how to create one.

 

The Scenario:

You need to build an application for the accounts-receivable department in which users can update a customer’s credit limit.  You’ll use the Common Data Service for Apps as your data source. The payment terms will update automatically based on current payment performance and the credit limit. The logic for the payment terms changes quarterly based on the overall market and company performance and must be maintained outside of your app.

 

Create a business rule:

Start by signing into PowerApps, and then

  • On the left navigation go to the data area and go to entities
  • Select the Account entity
  • Select the Business rules link
  • Click “Add business rule” in the command bar on the top of the screen

 

 

 

 

 

 

In the new tab, you can define the business logic.

 

Define your business logic:

  • Add a condition:
    • Click the New condition box on the top right, this will open the properties panel on the right
    • Change the display name to Credit Less than $500
    • Set the field to Credit Limit
    • Set the operator to Is less than or equal to
    • Set the value to 500.00
    • Click Apply

 

  • Add a component to the true flow (right of the condition box):
    • Select the component tab
    • Move  Set Field Value  component to the right of the condition box
    • Click on the item to enable the property tab
    • Set the Display Name to Set Payment Terms to Net 30
    • Set the field to Payment Terms
    • Set the value to Net 30
    • Click Apply

  • Add a component to the false flow (under the Condition box)
    • Select the component tab
    • Move Set Field Value component to the bottom of the condition box
    • Click on the item to enable the property tab
    • Set the Display Name to Set Payment Terms to Net 60
    • Set the field to Payment Terms
    • Set the Value to Net 60
    • Click Apply

 

Your business rule designer looks like this:

 

Rename your business rule by clicking the down arrow for New business rule on the top left of the window.  Name the business rule Payment Term Logic.

You must save and activate the business rule to use it in your app.  On the top right of the window, click the Save button, followed by the Activate button. When this succeeds, the bottom-left corner of the window changes from Draft to Activated.

You can now close the business-rule window and return to the business-rule grid for the Account entity, which looks like this:

 

 

 

Build a canvas app:

Now that you’ve created a business rule and set it to fire on the Account entity, you can create a canvas app for your accounts-receivable department.

Start by having PowerApps generate an app from your data:

  • On the PowerApps site, confirm that canvas appears in the bottom-left corner
  • Click Apps in the left navigation bar, and then click Create an app in the command bar
  • When PowerApps Studio opens, click Common Data Service under Start with your data, or click the next arrow and then select Common Data Service.
  • Under Choose a table, click Accounts, and then click Connect

In the app that you just generated, you’ll update some data that the user will interact with:

  • In BrowseScreen1
    • Click BrowseGallery1
    • Under Data in the property panel on the right, click Accounts
    • Change the layout to Title, subtitle, and body so that you can see all of the data in an account record
    • Set the Title2 property to name
    • Set the Subtitle2 property to credit limit
    • Set the Body2 property to payment terms label

  • In DetailScreen1
    • In the left navigation bar, click DetailForm1
    • In the data area of the property panel on the right, click Accounts
    • Hide all fields except Account Name and Credit Limit

  • In EditScreen1
    • Click EditForm1
    • In the Data area of the property panel on the right, click Accounts
    • Hide all fields except Account Name and Credit Limit

Now you can follow these steps to try out the canvas app and watch the values change:

  • Navigate back to BrowseScreen1, the first screen
  • Select the play button on the top right
  • Select the next arrow for the first account in your list (If you don’t have an account, create one by selecting the + button)
  • Select the pencil on the top right to edit the data
  • Change the credit limit to 1000
  • Select the checkmark on the top right

  • Select the back button to return to the list screen

The payment term is now automatically set to Net 60 for you

You now know how to create business rules in PowerApps and use them in your canvas apps.  Go try it on your own apps.  Navigate to http://web.powerapps.com, and create your first app that’s enabled with business rules!