Power Platform: Enhancing SharePoint Integrated Power Apps with Post-Submit Actions

Creating a seamless user experience in a SharePoint integrated Power App (Canvas App) can be challenging, especially when performing actions after form submission. Once a form is submitted, it closes, but the OnSuccess property allows you to run code post-submission.

In this blog, I’ll show you how to use the OnSuccess property to make changes to the newly created SharePoint item. Although you can’t use ThisItem or link directly to data cards, I’ll guide you through the process to ensure your app functions smoothly.

By the end, you’ll know how to enhance your Power App’s functionality and improve user experience. Let’s dive in!

Create a SharePoint list

  • Create a SharePoint list on any SharePoint site.
  • Add 1 text column named OnSuccesData.

Create the SharePoint integrated power app.

  • Open the created SharePoint list.
  • Click on Integrate, Power Apps, Customize Forms app.
  • This will create a basic SharePoint integrated power.
  • Remove the Attachments DataCard.
  • Click on the SharePointForm1 and add a custom datacard.
  • Add a label and a Text Input objects on the datacard.
  • Rename the label to lbl_OnSuccesData.
  • Rename the Text Input to txt_OnSuccesData.
  • Set the OnChange to the following code.
    • We need to store the Text value in a variable, because when you call directly for txt_OnSuccesData.Text it will work for editing items but not for creating items.
Set(varOnSuccesData, txt_OnSuccesData.Text);
  • Set the 2 objects below each other.
  • Set the text of the label to On Succes Data.
  • Set the Default of the text input to “”.
  • Create a new blank Power Automate flow from the power app.
  • Name the flow to Actions after submission.
  • Set the following text inputs.
    • ItemID
    • OnSuccesData
  • Add the SharePoint action Update item and set it for the earlier created SharePoint list.
  • Set the Id to ItemID from the power app.
  • Set On Succes Data to OnSuccesData from the power app.
  • Save the Power Automate flow.
  • Open the Power App again.
  • Select the OnSuccess property of the SharePointForm1 object.
  • Add before the ResetForm(Self); code the following code to start the Power Automate flow.
Actionsaftersubmission.Run(SharePointForm1.LastSubmit.ID, varOnSuccesData);
  • Test your app by putting a text in the title and a text in the second On Succes Data text input object.
  • After you save the form, the flow will start and store the On Succes Data in the SharePoint on success data column.

Power Platform: QR Codes in a Canvas App

Creating QR codes in a canvas app can significantly enhance user experience by providing quick access to links and information. QR Codes are the way to go if you want to share a link from a canvas app. In this blog, I will explore two efficient methods to generate QR codes: using the QR Code connector and an open source API, both options use the goqr.me API endpoint. These approaches will help streamline the process and offer flexibility in implementation, catering to various business needs. 

Methode 1: Using the QR Code connector

This method utilizes the GoQR (Independent Publisher) connector available in Power Apps to generate QR codes effortlessly.

  • Create a new blank canvas app.
  • Click on the Data tab and search for QR Code.
  • Click on the GoQR (Independent Publisher).
  • Then click on GoQR (Independent Publisher) to add the connection.
  • Add a Text input.
  • Add a button, name the button Create QR Code.
  • Set the OnSelect of the Create QR Code button to the following code.
Set(QRCode, 'GoQR(IndependentPublisher)'.Create(TextInput1.Text))
  • Add another button, name the button Reset QR Code.
  • Set the OnSelect of the Reset QR Code button to the following code.
Set(QRCode, Blank())
  • Add an image object.
  • Set the image property to the following code.
QRCode
  • Type an URL in the text input and click on Create QR Code to generate the QR Code.
  • Click on the Reset QR Code button to reset the QR Code.

Methode 2: Generating QR Code via a direct API call

For users who prefer a more direct approach, it is possible to call the goqr.me API directly from Power Apps. This method is flexible and does not require adding a connector.

  • Create a new blank canvas app.
  • Add a Text input.
  • Add a button, name the button Create QR Code.
  • Set the OnSelect of the Create QR Code button to the following code.
    Make sure the name of the text input is correct.
Set(QRCode, "https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=" & TextInput2.Text)
  • Add another button, name the button Reset QR Code.
  • Set the OnSelect of the Reset QR Code button to the following code.
Set(QRCode, Blank())
  • Add an image object.
  • Set the image property to the following code.
QRCode
  • Type an URL in the text input and click on Create QR Code to generate the QR Code.
  • Click on the Reset QR Code button to reset the QR Code.

Power Apps: Hidding and showing a component

I was tasked with developing a canvas app for a client that required each screen to include a popup element. The popup needs be openend by clicking an image, upon being clicked, it triggers a popup screen where users can compose a message. I utilized a Library Component and explored methods to control its visibility effectively. The challenge was ensuring that the message popup would appear when an image is clicked and disappear upon user interaction with a designated button. My solution involved manipulating the component’s dimensions — adjusting the height and width to expose only the image or to reveal the entire component. This technique successfully creates the perception of the popup screen being opened and closed by the user.

  • The first step is to create a solution with a canvas app and a component library.
  • In my example I named the component comp VIM Message.
  • Then open the component.
  • Set the size of the component to 640 by 640.
  • Add two custom output properties to the component named CompVIMHeigt and CompVIMWidth.
  • Set the component width to ‘comp VIM Message’.CompVIMWidth
  • Set the component height to ‘comp VIM Message’.CompVIMHeight
  • Set the component reset to Set(varCompHeight, 80);
  • Add an image element and set the following code on the Onselect. This will make the container visible and make the component bigger.
Set(varComVIMVisible, true);
Set(varCompHeight, 640);
Set(varCompWidth, 640);
  • You might need to adjust the numbers based on your needs.
  • Also set the X and Y properties on your image based on your needs. I use the following.
X = 'comp VIM Message'.Width - 55
Y = 15
  • Add a container with the element you need in the popup.
  • Set the following properties of the container.
Visible = varComVIMVisible
Height = 440
Width = 520
X = 75
Y = 190
Visible = varComVisible
  • Add two buttons in the container one called Cancel (in Dutch that would be Annuleren) and Send (in Dutch that would be Verzenden).
  • Set for both button the onselect to the following code, this will make the component smaller and hide the container.
Set(varCompHeight, 80);
Set(varCompWidth, 60);
Set(varComVIMVisible, false);
  • Open the canvas app and add the component comp CIM Message.
  • Insert the component into the canvas app.
  • Set the Heigth property to the following code. This will make sure the Height has a value when the canvas app page is loaded.
If(IsBlank('comp VIM Message_HS'.CompVIMHeight), 80, 'comp VIM Message_HS'.CompVIMHeight)
  • Set the Width property to the following code. This will make sure the Width has a value when the canvas app page is loaded.
If(IsBlank('comp VIM Message_HS'.CompVIMWidth), 60, 'comp VIM Message_HS'.CompVIMWidth)
  • Set the X property to the following code. This will make sure that the Image part of the component is on the left top side of the screen.
If('comp VIM Message_HS'.CompVIMWidth = 640, 'Home Screen'.Width - 640, 'Home Screen'.Width - 60)
  • Now run the canvas app and see if it works (it might not work in the play function in the edit mode).

From Bing Maps to Azure Maps

Bing maps has been an easy-to-use solution for getting location information in canvas apps, but this offering will be placed under the Azure Maps umbrella. While Bing Maps will continue to function for now, it’s essential to prepare for the transition. In this blog post I will explain how to use Azure Maps in a Canvas App. Please note that the locations shown in this post are not my actual location.

Azure Maps Services

  • First, we need to create a Azure Maps Account in a resource group (I will presume you know how to create a resource group).
  • Open your resource group.
  • Click on Create and search for and click on Azure Maps.
  • Click on Create.
  • Give the Azure Maps Account resource a name.
  • Select the correct Region and Pricing tier.
  • Agree with the terms and click on Review + Create.
  • Click on Create and wait for the deployment to be ready.
  • Click on Go to resource.
  • Click on Authentication and copy the Primary Key. You will need this in the Power Automate Flow.

The Power Automate Flow

  • Create a new Power Automate Flow and name it Azure maps get Postal Code.
  • Add as the trigger Power Apps (V2), with two text inputs called Longtitude and Latitude.
  • Next, we will add a HTTP action, this will call Azure Maps to get the location details based on the provided GPS location.
  • Set the method to Get.
  • Set the URI to the following code, make sure to put in your subscription-key (that is the primary key from the Azure Maps Account resource).
  • Set the Latitude and Longitude with the input fields form the trigger.
https://atlas.microsoft.com/search/address/reverse/json?api-version=1.0&subscription-key={YOUR KEY}&query={Latitude},{Longitude}
  • Add the action Parse JSON and give it the name Parse JSON – Location information.
  • Set the Content to the body of the HTTP call and set the schema as detailed in the linked file.
  • Add a compose action (if you want to only return the first found postal code).
  • The code for the input is as follows if you have named the Parse JSON action the same as I did.
first(body('Parse_JSON_-_Location_information')?['addresses'])?['address']?['postalCode']
  • Add the Respond to a Power App or flow action.
  • Add an output text called postalcode and add the compose as its value.
  • Your flow will now look like this.

The canvas app

We will now create the canvas app with a map that shows the user’s current location on a map, and a button to get the postal code of that location and a reset button. Please note this is not my actual location.

  • Create a new canvas app, I blank Phone canvas.
  • Click on Power Automate followed by Add flow to add the earlier created flow.
  • Add the map element to the canvas app.
  • Set the DefaultLatitude property with the following code.
Location.Latitude
  • Set the Location.Latitude property with the following code.
 Location.Longitude
  • Set DefaultLocation property with the following code.
true
  • If you want to see your Latitude and Logitude you can add labels to display the values.
  • Add a Label and set the Text property with the following code.
"Latitude: " & Location.Latitude
  • Add a Label and set the Text property with the following code.
"Longitude: " & Location.Longitude
  • Add a button and set the Text property with the following code.
"Get postal code"
  • Set following code on the OnSelect property. If needed update the code with your flow name, I used AzuremapsgetPostalCode.
Set(varPostalCode,AzuremapsgetPostalCode.Run(Location.Longitude, Location.Latitude));
  • Add a button and set the Text property with the following code.
"Reset"
  • Set following code on the OnSelect property.
Set(varPostalCode, Blank())
  • Add a label and set the Text property with the following code.
"Postal Code: " & varPostalCode.postalcode

Power Platform and Chat GPT

In today’s digital age, businesses are constantly looking for ways to streamline their processes and improve their customer experience. One way to do this is by leveraging the power of chatbots, which can quickly and efficiently answer customer inquiries. In this blog post, we will explore how to create a canvas app that uses Power Automate flow to ask ChatGPT API questions and display the response in the canvas app. By the end of this tutorial, you will have the tools and knowledge to build your own chatbot app that can answer your customers’ questions in real-time, enhancing their overall experience and increasing your operational efficiency. So, let’s get started!

Create a Chat GPT Api secret

  • Open the ChatGPT API site.
  • Login or create an account.
  • Click on Personal, followed by View API keys.
  • Click on Create new secret key and save the key in a password vault.

Creating the Power Automate Flow

  • Create a new Power Automate flow with the name Canvas app – Chat GPT.
  • Add as the trigger a PowerApps V2.
  • Add a text input with the name Question.
  • Add a HTTP action with the name Post to Chat GPT.
  • Set the Method to POST.
  • Set the URI to https://api.openai.com/v1/completions.
  • Set the header to Content-Type with value application/json.
  • Set a second header to Authorization with the value Bearer [API Secret].
  • Set the body to the following json code.
{
  "model": "text-davinci-003",
  "prompt": "triggerBody()['text']",
  "temperature": 0,
  "max_tokens": 4000
}
  • Add a Parse JSON action with the name Chat GPT Response.
  • Set the Content to Body (response of the HTTP call).
  • Set the following schema (update the schema is the response is different).
{
    "type": "object",
    "properties": {
        "id": {
            "type": "string"
        },
        "object": {
            "type": "string"
        },
        "created": {
            "type": "integer"
        },
        "model": {
            "type": "string"
        },
        "choices": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "text": {
                        "type": "string"
                    },
                    "index": {
                        "type": "integer"
                    },
                    "logprobs": {},
                    "finish_reason": {
                        "type": "string"
                    }
                },
                "required": [
                    "text",
                    "index",
                    "logprobs",
                    "finish_reason"
                ]
            }
        },
        "usage": {
            "type": "object",
            "properties": {
                "prompt_tokens": {
                    "type": "integer"
                },
                "completion_tokens": {
                    "type": "integer"
                },
                "total_tokens": {
                    "type": "integer"
                }
            }
        }
    }
}
  • Add the Respond to a PowerApp or Flow action.
  • Add a text output called ChatGPTRepsonse and add the response from Chat GPT with the following code.
first(body('HTTP_-_Post_to_Chat_GPT')?['choices'])?['text']
  • The overall Power Automate flow will look like this.

Creating the Canvas app

  • Open the Power Apps Studio and create a new canvas app.
  • Rename Screen1 to Home.
  • Add the Canvas app – Chat GPT Power Automate flow to the canvas app.
  • Add a Rectange Shape to the top of the canvas app with the name RectTitle.
  • Add a label over the RectTitle with the name lblChatGPT.
  • Set the Text to “Send your question to the all powerful Chat GPT AI bot”.
  • Add a label with the name lblGPTRepsonse.
  • Place the lblGPTRepsonse on the right side of the screen.
  • Add a text input with the name txtQuestion.
  • Place the txtQuestion on the left side of the screen.
  • Set the txtQuestion Default to “What is your question?”.
  • If you like add an Image with the name imgRobot and add an image of a robot in the Image property.
  • Place the imgRobot left and next to the lblGPTRepsonse.
  • Add a button with the name btnSendQuestion.
  • Set the following code on the Onselect of the btnSendQuestion.
    • This will save the response in the variable repsonsegpt.
    • Start the flow with the text provided in the textQuestion text input box.
Set(responsegpt, 'Canvasapp-ChatGPT'.Run(txtQuestion.Text).chatgptrespondse)

Create and delete B2C accounts for Dataverse Contact

Today, we’ll be discussing a crucial aspect of B2C account management – the creation and deletion of B2C accounts in response to changes in the Dataverse Contact. This is an important topic for businesses that deal with external Power Pages user (contacts) that want to ensure the security of their records and Power Pages. In this post I will explain how to create or delete B2C accounts that are connected to a Dataverse Contact. So, let’s dive in!

Create a B2C account when a Dataverse Contact is created

Whenever a new contact is created a new B2C account needs to be created automatically that is linked to the contact. This is done thought the email address of the contact and the Azure B2C account id. These automations will limit the amount of manual admin work.

  • Create a new Power Automate flow with the name Create B2C user for Dataverse Contact.
  • Add the Dataverse trigger When a row is added.
  • Set the Change type to Added.
  • Set the Table name to Contacts.
  • Set the Scope to Organization.
  • Create the following 3 variables.
  • You will need to create an Application Registration in the B2C tenant with the following permissions.
Permission typePermissions (from least to most privileged)
Delegated (work or school account)User.ReadWrite.All, Directory.ReadWrite.All
Delegated (personal Microsoft account)
Not supported
ApplicationUser.ReadWrite.All, Directory.ReadWrite.All
  • Store the Client ID, Tenant ID and Secrect in the corresponding variables.
  • Add a HTTP action called HTTP – Delete User to the flow.
  • Set the Method to: Post.
  • Set the URI to the following code.
https://graph.microsoft.com/v1.0/users
  • Set the body to the following code.
  • In my scenario the user will not be using the password but the one-time password from B2C. That’s why I have added a guid twice as the password.
  • This call will create an account of the type email address which allows for any valid email to be used. The email does not have to be part of the B2C domain.
  • Parse the JSON response of the HTTP – Create User call.
  • Add the Dataverse action Update a row.
  • Set the Table name to Contact.
  • Set the Row id to the contact id of the trigger.
  • Add the id that was returned by the HTTP call that created the B2C account.
  • Save the flow.

Delete B2C account when Dataverse Contact is deleted

In my scenario I am maintaining the Power Pages contacts within a canvas app, and when a contact is deleted the associated B2C account needs to be deleted too.

  • Create a new Power Automate flow with a Power Apps (V2) trigger with the name Delete B2C users for deleted Dataverse Contact.
  • Add an input Text field names ActiveDirectoryID.
    • This is the Object ID of the Azure B2C Active Directory User connected to the Contact.
  • Create the following 3 variables.
  • You will need to create an Application Registration in the B2C tenant with the following permissions.
Permission typePermissions (from least to most privileged)
Delegated (work or school account)User.ReadWrite.All
Delegated (personal Microsoft account)
Not supported
ApplicationUser.ReadWrite.All
  • Store the Client ID, Tenant ID and Secret in the corresponding variables.
  • Add a HTTP action called HTTP – Delete User to the flow.
  • Set the Method to: Delete.
  • Set the URI to the following code.
https://graph.microsoft.com/v1.0/users/
  • Add the PowerApp (V2) parameter ActiveDirectoryID to the end of the URI.
  • Set the Tenant, Client ID and Secret fields with their corresponding variables.
  • Set the Authentication to Active Directory OAuth.
  • Set the Audience to the following code.
https://graph.microsoft.com
  • Save the Power Automate Flow.
  • Open or create a canvas app (Power Apps).
  • Open the Power Automate panel in the canvas app.
  • Add the Delete B2C users for deleted Dataverse Contact Power Automate flow.
  • Add a gallery with the source set to the Dataverse Contact table.
  • Add a recycle bin or other delete Icon to the gallery.
  • Add the following code to the recycle bin icon under OnSelect.
    • This will remove the contact record.
    • Starts the Power Automate Flow and sending the User Name (Users B2C object ID).
    • Notifies the users.
Remove(Contacts, ThisItem);
DeleteB2CuserfordeletedDataverseContact.Run(ThisItem.'User Name');
Notify("Record deleted successfully", NotificationType.Success);
  • Save and publish the canvas app.