Dynamics 365 — PowerApps tips and tricks

Satya Kar
Capgemini Microsoft Blog
6 min readOct 24, 2018

PowerApps is a collection of services, apps, and connectors that work together to let you to easily build business apps that runs on browsers and in phone or tablet without any coding experience needed. PowerApps can connect to cloud services and data sources and instantly share your apps so co-workers across the company or across the world can use them on their phones and tablets.

I was exploring how to build a PowerApp using Dynamics 365 data source. It’s so easy to build the user interface from Dynamics data source but found some out-of-box limitations which can be achieved using alternate solutions. I will outline those tips and tricks in this blog.

If you’re not familiar with Power Apps then start reading documentation.

Display mandatory fields in Power App Editscreen:

PowerApp does not enforce a field to display as business required as shown in Dynamics 365. To make the field mandatory you can write formula and set control properties. In this example I have chosen the lead entity and made Topic and First Name mandatory in the edit screen.

  • Expand the topic and first name data card -> select star label control -> Set the visible property to true.
  • Select the Edit Form -> Set the OnSelect property of submit icon as below. This formula will validate if data card value is blank, will set each corresponding variable to true, else it will submit the edit form.

If(IsBlank(DataCardValue14.Text), UpdateContext({topicErrorMessage: true}), IsBlank(DataCardValue12.Text), UpdateContext({firstnameErrorMessage: true}), SubmitForm(EditForm1))

  • Now set the error message label control Text and set the visible property to corresponding variable for each data card.
  • Set the below properties for Topic Error control: Text — Topic is mandatory, Visible — topicErrorMessage
  • Set the below properties for First Name Error control: Text — First Name is mandatory, Visible — firstnameErrorMessage
  • Reset the error message variable and set the default value to false on OnSelect property of cancel icon and OnSuccess property of editform as:

UpdateContext({topicErrorMessage: false}); UpdateContext({firstnameErrorMessage: false})

  • On create of a new lead record if the Topic and First Name does not have any value and you click on submit icon, the error message will be displayed.

Filter records based on logged-in user in PowerApps Browse Screen:

PowerApps does not show multiple views like My entity, Active entity views available in Dynamics 365. By default, PowerApps browse screen shows all the records for the selected data source and you can add users data source and formula to filter the records based on logged-in user. In this example I will show My Lead like My Entity view in Dynamics CRM.

  • Add user entity. Select View -> Data sources -> Add data source.
  • Select Dynamics 365 connection -> Select Users entity -> Click on connect.
  • Select Browse Gallery and set its Items Property to below formula to filter the leads created by current user.

SortByColumns(Search(Filter(Leads, _ownerid_value = LookUp(Users, internalemailaddress = User().Email, systemuserid)), TextSearchBox1.Text, “emailaddress1”), “emailaddress1”, If(SortDescending1, Descending, Ascending))

Use of Lookup fields in PowerApps Screens:

PowerApps does not support showing the name of a Dynamics lookup field. By default the lookup field shows the GUID value of referenced record and you can add the reference entity data source and formula to display the name. In this example I have selected the Dynamics lead entity as main data source and will show you how to display the name of parent account for lead lookup field value.

For lead entity there is a lookup filed named parent account for lead. When you add this field into screen, by default it shows GUID of parent account as shown below.

Follow the steps below to the display the name in each screen.

  • Add Account entity. Select View -> Data sources -> Add data source.
  • Select Dynamics 365 connection -> Select Accounts entity -> Click on connect.
  • Browse Screen: — Select the parent account for lead field and set the Text property as below formula. Now you can see the name of parent account in the lookup field.

LookUp(Accounts, accountid = ThisItem._parentaccountid_value, name)

  • Detail Screen: — Expand the parent account for lead data card -> select the data card value control-> set the Text property as below formula. Now you can see the name of parent account in the lookup field.

LookUp(Accounts, accountid = ThisItem._parentaccountid_value, name)

  • Edit Screen: — For lookup filed name in the edit screen add search icon, create new blank screen and add formula. Follow the steps below to make it working.
  • Insert -> New Screen -> Blank.
  • Add vertical gallery control and sets it items property to Accounts. Select the name field in the title.
  • Select the next arrow and set its OnSelect property to :

ClearCollect(accountTobeAdded, {account: accountLookupGallery.Selected}); Back()

accountTobeAdded — Variable to store the selected account.

  • Expand the edit screen -> Select the edit form -> Select the parent account for lead data card -> Go to advance properties and unlock the data card.
  • After unlocking the data card add a search icon inside the data card -> Select the search icon and set its OnSelect property to:

Navigate(AccountLookup,ScreenTransition.Fade);Clear(accountTobeAdded)

  • Now select the data card value of parent account for lead and sets it default value to:

If(IsBlank(First(accountTobeAdded).account.accountid),LookUp(Accounts, accountid = ThisItem._parentaccountid_value, name),First(accountTobeAdded).account.name)

  • Again, select the parent account for lead data card and set its Default value to:

First(accountTobeAdded).account.accountid

  • Select the edit form and set its OnSuccess property to:

Clear(accountTobeAdded);

Hope this helps! please comment and share your tips and tricks. Happy learning!!

--

--