Adv Hands On Lab 4: Embedding PowerApps canvas app into a model driven application
Contoso has built a model-driven app to challenge their employees to innovate. The way the app works is Contoso management can submit challenges and then employees can submit ideas. For example, a challenge might be “Reduce factory emissions by 10%.” Employees can submit ideas for challenges and get funded once they get enough votes.
Contoso would like to announce new challenges in Microsoft Teams by posting some information about the challenge. Contoso’s users would like to be able to create this post from the model-driven Innovation Challenge app they use to manage the challenges.
You will be building an embedded canvas app that will let users start discussions without leaving the Innovation Challenge application.
Environment
The lab requires a PowerApps environment with a Common Data Service database created and the sample apps installed.
Requirements
The following have been identified as requirements you must implement to complete the project.
- R0 – User must be able to start new Teams discussion from the existing Innovation Challenge application.
- R1 – User must be able to select the Team in which they would like to start the discussion.
- R2 – User must be able to select the Channel in which they would like to start the discussion.
- R3 – The Challenge name must be included in the chat message.
- R4 – User should be able to edit the message before posting it.
- R5 – The embedded canvas should not be visible if a discussion was already started.
Exercise 1 – Canvas App in Model-Driven App
Task 1: Connect to Teams
In this task, you will add a Microsoft Teams trial to your tenant (if needed) and create a couple Teams and channels.
- Navigate to https://teams.microsoft.com/
- Login with your admin user.
- Click Use the Web App Instead.
- Click Start and wait for Teams to start. Note: if you already have a Teams licensed user, this step may not be needed.
- Select Teams and click Create Team.
- Click Build Team from Scratch.
- Select Public.
- Enter Team One for Team name and click Create.
- Click Skip when asked to add members to the team.
- Right click on Team One and select Add Channel.
- Enter Channel One for Channel Name and click Add.
- Right click Team One again and select Add Channel.
- Enter Channel Two for Channel Name and click Add.
- On the bottom left, click Manage Teams.
- Click Create a Team.
- Select Build a Team from Scrach.
- Select Public.
- Enter Team Two for Team Name and click Create.
- Click Skip.
- Right click on Team Two and select Add Channel.
- Enter Channel One for Channel Name and click Add.
- Right click on Team Two again and select Add Channel.
- Enter Channel Two for Channel Name and click Add.
- You should now have two teams with three channels each.
Task 2: Create Solution
In this task, you will create a publisher, create a new solution, add an existing entity to the solution, and add new field.
- Navigate to https://make.powerapps.com/ and make sure you are in the correct environment.
- Select Solutions and click New Solution.
- Enter Contoso Embedded for Display Name, click on the Publisher dropdown and click + Publisher.
- Enter Contoso for Display Name, contoso for Prefix and click Save and Close.
- Select Contoso for Publisher, enter 1.0.0.0 for Version and click Create.
- Click to open the solution you just created.
- Click Add Existing and select Entity.
- Select the Challenge entity and click Next. If you have difficulty locating the Challenge entity, use the search box to find and select it.
- Click Select Components.
- Select the Forms tab.
- Select all three forms and click Add. Note: Ideally we would just select the Main Form that we are going to edit, however due to a current bug that type of form is not showing and all three forms are named Information.
- Click Add again.
- Click to open the Challenge entity.
- Select the Fields tab and click Add Field.
-
Enter Started Date for Display Name select Date Only for Data Type and click Done.
Note: Currently Embeded Canvas Apps can only be created as a control for a field or a subgrid, you can’t just put a canvas app unbound to any data.
- Click Save Entity.
Task 3: Add Field to the Form
In this task, you will add the new field to the main form.
- Select the Forms tab.
- Hover over the Main form, click on the … More Commands and select Edit Form (Preview).
- Select the Contributed Ideas section.
- Click Add Control and select 1-Column Section.
- Go to the Properties pane, change the Section Label to Start Team Chat, change the Name to start_team_chat_section.
- Click Add Field.
- Select Started Date.
- Click Save.
- Click Switch to Classic. Note: Currently, you can only create the embeded canvas app and change the controls for a field from the classic form editor. In the future you will be able to do this without changing to classic.
Do not navigate away from this page
Task 4: Add Canvas App
In this task, you will create the canvas application. Since you are working in a solution, the canvas app you create here will also be included in the solution.
- Double click the Started Date field. In some browsers you may need to select the item and look for form properties in the header instead.
- Uncheck Display Label.
- Select the Controls tab and click Add Control.
- Select Canvas App and click Add.
- Select Web.
- Click Customize to create your canvas app in the PowerApps Studio. This will launch an app designer browser tab.
- Click File and select Save.
- Enter Start Group Discussion for Name and click Save.
- Click on Back button in the PowerApps console (not the browser back button).
- Right click on Form1 and select Delete.
- Rename the Screen teamsScreen.
- Select the View tab and click Data Sources.
- Go to the Data pane and click Add
Data Source.
- Select Add New Connection.
- Search for Teams and select Microsoft Teams.
- Click Create.
- Click Add Data Source again.
- Search for Common Data Service and select it.
- Click Create.
- Select the Challenges entity and click Connect.
- Close the Data pane.
- Select the Insert tab, click Controls and select Drop Down.
- Right click on Dropdown1 and select Rename.
- Rename it teamsDropdown.
- Set the Items property to the formula below. If you have difficulty with copy/paste then type the formula manually. This formula will list the available teams in the dropbox
MicrosoftTeams.GetAllTeams().value
- Go to the Properties pane and click Advanced.
- Scroll down to the Data section and select displayName for Value.
- Click Controls and select Dropdown again.
- Rename the dropdown channelsDropdown.
- Set the Items property to the formula below. This formula will show the channels of the selected team in the second dropdown.
If(!IsBlank(teamsDropdown.Selected),MicrosoftTeams.GetChannelsForGroup(teamsDropdown.Selected.id).value)
- Go to the Properties pane and select displayName for Value.
- Select the teamsScreen.
- Select the Insert tab, click Text and select Rich Text Editor.
- Rename the RichTextEditor1 to messageText.
- Arrange the controls on the screen as shown below.
- Select the messageText control and set the Default value to the formula below. This formula will build the chat message.
Concatenate(“New Challenge available <strong>”, ModelDrivenFormIntegration.Item.sample_name , “</strong>. Go create your new ideas.”)
- Select the teamsScreen and click Button.
- Set OnSelect to the formula below. This formula will post the message to the selected channel.
MicrosoftTeams.PostMessageToChannel(teamsDropdown.Selected.id,channelsDropdown.Selected.id,{body:{content: messageText.HtmlText,contentType:1}})
- Change the Text value to Send.
- Rename the button Start Discussion.
- Move your Send button and place it below the text box. Resize it to be the same width as the textbox.
- Your canvas application will now look like the image below.
- Click File and select Save.
- Click Publish.
- Click Publish this Version.
- Click Close.
- Close the app designer browser tab.
- Click OK.
- Click Save.
- Click Publish.
- Click Save and Close.
- Close the form designer browser tab.
- Click Done.
- Select Solutions and click Publish All Customizations.
Task 5: Test the Application
In this task, you will test the application.
- Go to https://web.powerapps.com
- Select Apps.
- Click to open the Innovation Challenge application.
- Select Challenges.
- Double click to open one of the challenges.
- The Canvas app should load in the Start Group Discussion section and the challenge name will be included in the text.
- Start a new browser tab and navigate to https://teams.microsoft.com/
- Login if prompted.
- Go back to the Innovation Challenge app and select a Team from the first dropdown.
- Select Channel from the second dropdown.
- Click Send. You may edit the message.
- Go back to Teams. A new chat should get started in the team and channel you selected.
Bonus: Edit your form to look more like the image below
Exercise 2 – Update and Refresh
In this exercise, you will update the challenge record from the canvas application and show the updated record in the model-driven application.
Task 1: Add Field to the Form
In this task, you will add the Started Date field to the Challenge main form.
- Navigate to https://web.powerapps.com/ and make sure you are in the correct environment.
- Select Solutions and click to open the solution you created.
- Click to open the Challenge entity.
- Select Forms and click to open the Main form.
- Uncheck the Show Only Unused Fields checkbox.
- Select the Start Team Chat section, search for Started Date and click on it.
- Drag the new field and place it above the field you added in Exercise 1.
- Click Save.
- Close the form editor browser tab.
- Click Done.
- Select Solutions and click Publish All Customizations.
Task 2: Update Field and Refresh Form
In this task, you will update the Started Date value and refresh the form from the Canvas application.
- Navigate to https://web.powerapps.com/ and make sure you are in the correct environment.
- Select Solutions and open the solution you created.
- Select Apps, select the Start Group Discussion application, and click Edit.
- Select the Start Discussion button.
- Select the OnSelect property, place your cursor at the beginning of the existing function and paste the formula below. There are two functions in this formula, the Patch function will update the Started Date of the Challenge records and the ModelDrivenFormIntegration.RefreshForm will refresh the form.
Patch(Challenges, First( Filter(Challenges, Challenge = ModelDrivenFormIntegration.Item.sample_challengeid)), {‘Started Date’: Now()});ModelDrivenFormIntegration.RefreshForm(false);
- Click File and Save.
- Click Publish.
- Click Publish this Version.
- Click the app designer browser tab.
- Click Done.
- Select Apps and click to open the Innovation Challenge application.
- Select the Challenges and open one of the records.
- Locate the embedded canvas application and make sure the Started Date field is empty.
- Click Send.
- The Started Date field should now have today’s date.
Bonus – Hide Embedded Canvas
In this exercise, you will create a business rule that will hide the embedded canvas application if started date field has a value.
Task 1: Create Business Rule
In this task, you will create the business rule.
- Navigate to https://web.powerapps.com/ and make sure you are in the correct environment.
- Select Solutions and open the solution you created.
- Click to open the Challenge entity.
- Select the Business Rules tab and click Add Business Rule.
- Select the Condition, go to the Properties pane, and enter Check Started Date for Display Name.
- Go to Rule 1, select Entity for Source, select Started Date for Field, Contains Data for Operator, and click Apply.
- Click Add and select Set Visibility.
- Add it to the true side of the condition.
- Select the New Action, go to the Properties pane, enter Hide Canvas for Display Name, select Started Date for Field, select No for Visible and click Apply.
- Click Add and select Set Visibility again.
- Add it to the False side of the condition.
- Select the New Action, go to then Properties pane, provide the value shown in the image below and click Apply.
- Your Business Rule will look like the image below. Click Save.
- Click Activate.
- Click Activate again.
- Close the Business Rule editor browser tab.
- Click Done.
Task 2: Test Business Rule
In this task, you will test the business rule you created.
- Navigate to https://make.powerapps.com/ and make sure you are in the correct environment.
- Select Apps and click to open the Innovation Challenge application.
- Select Challenges and open one of the records. Select a record different from the one you used to test the canvas app.
- Go to the embedded canvas application and make sure it is visible on the form and the started date is empty.
- Click Send.
- The form should refresh, and the embedded canvas application will no longer be visible on the form.
Bonus – Open Quick Create Form
In this exercise, you will open a quick create form from the canvas application.
Task 1: Open Quick Create Form
In this task, you will add a button to the canvas application, this button will open a quick create form.
- Navigate to https://web.powerapps.com/ and make sure you are in the correct environment.
- Select Solutions and open the solution you created.
- Click on the … More Commands button of the Start Group Discussion application and select Edit.
- Select the teamScreen.
- Select the Insert tab and click Button.
- Rename the button QuickCreateButton.
- Place the button below the Send button and resize it.
- Change the button text Create Team Project.
- Select the OnSelect property of the button and paste the formula below. This formula will open the team project quick create form.
ModelDrivenFormIntegration.OpenQuickCreateForm(“sample_teamproject”)
- Click File and Save.
- Click Publish.
- Click Publish this Version.
- Click Close.
- Close the app designer browser tab.
- Click Done.
Task 2: Test Quick Create
In this task, you will test the embedded canvas application and see that the quick create form opens.
- Navigate to https://web.powerapps.com/ and make sure you are in the correct.
- Select Apps and open the Innovation Challenge application.
- Select Challenges and open a record you haven’t used to for testing before.
- Go to the embedded canvas application and click on the Create Team Project button.
- Quick Create form should open, provide the information below and click Save and Close.
- Select Team Projects. The Test Project should be in the list of records.
Comments
-
Adv Hands On Lab 4: Embedding PowerApps canvas app into a model driven application
If we integrate a canvas on model driven app form will that work in offline mode?
-
Adv Hands On Lab 4: Embedding PowerApps canvas app into a model driven application
Excuse me . I followed your steps and stopped at the task 2 because I could not found the sample_challenge data in Dataverse. Would you mind sharing your solution?
*This post is locked for comments