Home > PowerApps > [Step by Step] Canvas App | Dataverse | Filter, Patch, For All, Lookup

[Step by Step] Canvas App | Dataverse | Filter, Patch, For All, Lookup

In this article, lets understand the Filter, Patch, For All and more functions and formulas using following ‘Car and Customer’ scenario. I will be using Dataverse formerly CDS as Data Source.

  • Create a ‘Manufacturer’ table to store Car manufactures.
  • Use OOB ‘Contact’ table to store Customers.
  • Create a ‘Cars’ table to store Cars.
    • Configure ‘Contact’ and ‘Manufacturer’ look ups in ‘Cars’ table.

Lets proceed first by understanding ‘Data Model’ and then with creating ‘Canvas’ App.

Dataverse Data Model:

  • ‘Cars’ form with ‘Manufacturer’ and ‘Customers’ look up.
  • ‘Cars’ view.

Configuring Canvas App

Lets build the Canvas App, with following features:

  • Add “Manufacturers”, “Cars” and “Contact” (i.e., Customer) Data Sources.
  • Add ‘combManufacture’ Combo box to show ‘Active’ Manufacturers.
    • Select ‘Data source’ as ‘Manufacturers’.
    • Select ‘Active Manufacturers’ from the ‘Views’.
  • Add ‘combCustomers‘ Combo box to show ‘Active’ Customers (i.e., Contacts).
    • Select ‘Data source’ as ‘Contacts’.
    • Select ‘Active Contacts’ from the ‘Views’.
  • Filter the ‘Cars’ by selected ‘Manufacturer’ and set to ‘collCars’ collection variable.
    • Formula : ClearCollect(collCars,Filter(Cars,Manufacturer.Manufacturer=combManufacture.Selected.Manufacturer));
  • Add ‘galCars’ Gallery control and select the ‘Data Source’ as the collection variable from previous step.
  • In the Gallery, add a ‘Checkbox’ control to enable selection and a Label to show the ‘Customer’.
  • On check of ‘Checkbox’ add the selected ‘Car’ to ‘selCars’ collection variable, using ‘OnCheck’ event.
    • Formula : Collect(selCars, ThisItem);
  • On uncheck of ‘Checkbox’ remove the selected ‘Car’ from ‘selCars’ collection variable, using ‘OnUncheck’ event.
    • Formula: Remove(selCars, ThisItem);
  • Add ‘Set Owner’ button to map the selected Cars and Customer.
    • First move the selected ‘Cars’ from ‘selCars’ collection to ‘tempCollection‘ by renaming ‘Primary’ column to “ID” using RenameColumns function.
    • Use ForAll function to loop through ‘tempCollection‘ (i.e., Selected Cars) and update the ‘Contact’ lookup with ‘combCustomers‘ selected record using Patch function.
    • Reset the Cars Gallery(i.e., Reset(galCars)) to refresh.
    • Display the message using Notify function.
    • Clear the collection variables.
    • Formula: ClearCollect(tempCollection,RenameColumns(selCars,”crbb8_carid”,”ID”));ForAll(tempCollection,Patch(Cars,LookUp(Cars,Car=ID),{Contact:combCustomers.Selected}));Reset(galCars);Notify(“Update Successful..”,NotificationType.Success);Clear(tempCollection);Clear(selCars);
  • Add ‘Clear Owner’ button to unmap the selected Cars and Customer.
    • To unmap the Customer with Car, clear ‘Contact’ look up by setting ‘Blank()’ function (i.e., {Contact:Blank()}).
    • Use ‘For All’ and ‘Patch’ functions as above to update the record.
    • Formula : ClearCollect(tempCollection,RenameColumns(selCars,”crbb8_carid”,”ID”));ForAll(tempCollection,Patch(Cars,LookUp(Cars,Car=ID),{Contact:Blank()}));Reset(galCars);Notify(“Update Successful..”,NotificationType.Success);
  • Now run the App and you should see screen as below.

Refer this article for PowerApps functions and formulas.

🙂

Categories: PowerApps Tags: , ,
  1. Sanjay
    January 4, 2021 at 9:05 PM

    Hi Rajeev, I am trying to call Power BI UI application vis iframe from DYnamic but getting below issue.

    When calling below power BI URL from web resource then getting below error. It is related to Referrer Policy: strict-origin-when-cross-origin

    Like to check whether you encounter such CORS related issue from Dynamic ?
    app.powerbi.com refused to connect.

    when developer mode F12 , below is the error.

    Request Method: GET
    Status Code: 302
    Remote Address: 168.63.255.175:443
    Referrer Policy: strict-origin-when-cross-origin

    Any idea?

  2. January 5, 2021 at 5:20 PM

    Did not try hosting in iFrame. Hope you are familiar with surfacing Power BI dashboard https://rajeevpentyala.com/2017/04/15/step-by-step-surface-power-bi-reports-in-dynamics-crm-dashboard/.

  1. No trackbacks yet.

Leave a Reply to Rajeev Pentyala Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: