Power App: Tips & Tricks

Today, we will delve into some practical tips and tricks that can enhance your experience while working with Power Apps. Whether you’re a seasoned developer or just starting out, these tips will help you streamline your workflow and make the most out of the Power Platform.

In this post, we’ll cover various aspects of working with Dataverse forms in canvas apps, including how to handle different form modes, retrieve the last submitted data, and reset variables in SharePoint-integrated Power Apps. Additionally, we’ll explore how to use the concurrent function to load multiple data sources quickly, get current user details, and cache data for better performance.

Form modes

When working with a Dataverse form in a canvas app, you sometimes need different behavior for the edit, new, or view mode of the form. Each mode is represented by a number, and you can use the following code to check the current FormMode. Form2 is the name of the form.

If(Form2.Mode = 0, "Edit", Form2.Mode = 2, "View", "New")
Enum NameNumeric Value
FormMode.Edit0
FormMode.New1
FormMode.View2

It can also be done by comparing the Mode of the form SharePointForm1.LastSubmit.ID with the FormMode.Edit / View or New code.

If(Form2.Mode = FormMode.Edit, "Edit", Form2.Mode = FormMode.View, "View", "New")

Last submitted data

When working with a form to submit data to Dataverse you can get the last submitted data. You can get the ID of the created record by calling the LastSubmit followed by the name of the ID column.

Form1.LastSubmit.Contact

This can also be done with a SharePoint integration power app by calling the LastSubmit code from the SharePoint form.

SharePointForm1.LastSubmit.ID

Reset variables in SharePoint integrated Power App

When you set variables in a SharePoint integrated Power App don’t forget to reset them when the user closes the app either resetting the variables in the OnCancel or OnSave or resetting them when the form gets opened.

Set(varStatus, Blank());
Set(varFlag, false);

Use concurrent to load multiple sources quicker

When you want to store multiple sources locally, you can load them in a collect one after the other.

ClearCollect(Account, Accounts);
ClearCollect(Contact, Contacts);

But you can also load them in parallel by using the concurrent function. This will load them faster by loading them at the same time.

Concurrent(
    ClearCollect(colAccount, Accounts),
    ClearCollect(colContact, Contacts)
);

Get current users details

You can get the current user’s details by using the User() function.

User().EntraObjectId;
User().Email;
User().FullName;
User().Image;

Cache data that does not change but is used in multiple locations

When you are calling the same function again to access a resource to get the same data it is better (faster) to retrieve it once and store it in a variable.

Set(varCurrentUserName

Set(varUsername, User().FullName);
Set(varMyAccountName, LookUp(Accounts, 'Account Name' = "Contoso, Ltd."));

Drop-down not showing the correct values

Sometimes when you add a drop-down to a canvas app the displayed values are item 1, item 2 etc. Instead of the actual values. This happens when the drop-down list options are not loaded correctly.

Go to the DisplayFields property of the drop-down and set the it to [“Value2”] instead of [“Value”]. The canvas app will see that this is incorrect and change it back to [“Value”] and refresh the drop-down values. Now all the correct values will be visible.

Power App: How to export and import a SharePoint Power App Form

At this moment there is no out-of-the-box way to export/import a SharePoint Power App form between SharePoint list. Even when you duplicate the SharePoint List the custom SharePoint Power App form will not be duplicated. But fear not, there is a way to transfer the form. However its not for the faint of heart you will need to manual edit the forms code.

Exporting the form

  • Open the settings of the SharePoint list with the SharePoint Power App form.
  • Click on Form settings.
  • Click on See versions and usage; this will open the app in the Power App Studio.
  • Click on Export package.
  • Give the package a name and set the import setup to Create as new.
  • Click on Export.

Duplicate the SharePoint list

We will need a exact copy of the original SharePoint list, otherwise the names (references) will not be the same.

  • Click in SharePoint on the menu on the left on the +
  • Click on Existing list
  • Select the SharePoint site and the select your list, my list is called My Demo List.
  • Leave the name the same and click on Create.
  • A duplicated list is now created, but without the SharePoint Power App form.
  • For the manual changes we will need to get the list id
  • Open de list settings and copy the list ID from the URL.

Manually changing the references

  • Navigate to the exported SharePoint Power App form create a copy of it and unzip it.
  • Open the unzipped folder.
  • Navigate to Microsoft.PowerApps – Apps – [numeric value].
  • Open the JSON file with only numbers in its name in your favorite code editor (I am using Visual Studio Code).
  • Find the old list id and replace it with the new ID. Depended on you app, the ID might need to be replaces multiple times.
  • Now find the site URLs that reference the old site and change them to the new site. There might be multiple URLs that need to be updated, my app had 5.
  • Save the changes to the file.
  • Now we need to unzip the MSAPP File.
  • Change the type from msapp to zip and unzip the folder.
  • Open the unzipped folder.
  • Open the Properties.json and change the old URL to the new URL.
  • Open the DataSources file.
  • Change al the old URLs to the new URL, be aware there are some partial URLs that need to be changed.
  • Save all the changes and remake the zip file.
  • Remove the old MSAPP file.
  • Rezip the folder and set the name to be exactly the same as the old msapp file.
  • Make sure you did not add an extra folder layer to the new zip file.
  • Change the file type of the zip file to msapp.
  • Remove the unzipped folder.
  • Go to the top level of the folder and rezip the whole app.
  • Make sure you did not add an extra folder layer to the new zip file.

Importing the form

  • Upload the updated exported package (zip).
  • Change the name of the app, the names of app need to be unique.
  • If required setup the connections.
  • If required select the flows.
  • Click on import.
  • Wait for the import to finish.
  • Open the new (duplicated) SharePoint list.
  • Click on Integrate – Power Apps – Customize forms.
  • This will open the imported app.
  • Publish the app.
  • Go back to the list and create an item, the SharePoint Power App form will now be opened.
    • You might need to refresh the page for the app to appear.

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 Platform: Analyse email attachments with AI

In today’s fast-paced business environment, leveraging automation and artificial intelligence (AI) is crucial for maintaining efficiency and gaining insights. This blog post explores how to create a Power Automate flow that reads emails with attachments, extracts content from images or PDF documents using AI, and can perform various analyses on the extracted text. For instance, you can determine the sentiment, generate summaries, or classify emails as purchase requests or complaints and routing then accordingly. By integrating these advanced technologies, businesses can streamline their processes, enhance decision-making, and stay ahead in the competitive landscape.

AI Generated image

Create an AI model

First, we need to create a custom AI document model or AI Prompt that receives the PDF content and analyses it. But off course we can also use a default model. In this example we will be using the default AI Sentiment.

Create a Power Automate Flow

In this flow we will get all the attachments from the email and get the content ready to be sent for a sentiment analysis.

  • Create a Power Automate flow with the trigger, When a new email arrives in a shared mailbox (V2).
  • Connect this with the required email box and select the option Include Attachments to Yes.
  • Add the action Initialize variable and call it Initialize variable – Attachment Content.
  • Add a Scope action called Scope – Get PDF Content.
  • We are going to combine all the content of all the found PDF attachments into one variable. You could also send each attachment file separately.
  • First, we need to filter the attachment files to only get the PDF file.
  • Add a Filter Array action and call it Filter Array – Attachment for PDF.
  • Set the from to Attachments.
  • Set the first value to Attachment Content type.
  • Set the filter to is equal to.
  • Set the second value to application/pdf.
  • Add an Append to string variable action and name it Append to string variable – Attachment Content.
  • Set the Name to Attachment Content.
  • Set the Value to Content (from the filter array) – .
  • An apply to each will be automaticallycreated, name it Apply to each – Found PDF.
  • Add a Recognize text in an image or a PDF document below the apply to each.
  • Set the image to Attachment Content.
  • Add a Scope and name it Scope – AI Sentiment.
  • Add a Create Text with GPT using a prompt action and name it Create Text with GPT using a prompt – Get sentiment.
  • Set AI Sentiment as the Prompt.
  • Set Input Text to Attachment Content variable.
  • Your flow now looks like this.

Power Platform: Use AI to evaluate every incoming email

Leveraging AI for email management not only saves time but also reduces the risk of human error. By automating the evaluation process, businesses can ensure that important emails, such as orders, are promptly and accurately identified, allowing for quicker response times and improved customer satisfaction. Embracing AI in email workflows is a smart move towards greater productivity and operational excellence.

In this article, I explain how to create an AI prompt model using Microsoft GPT to streamline email processing. By integrating Power Automate, the flow sends the content of each new email to the AI model, which then determines if the email is an order. If identified as an order, the AI responds with a JSON output indicating a positive result. This approach enhances the efficiency and accuracy of order processing through intelligent automation.

Create an AI model

For this blog I create a simple AI prompt to evaluate if a incoming email is a request for an order. The actual prompt is more complicated but confidential.

  • Open the AI hub aka AI Builder and select the Create text with GPT using a prompt.
  • Give the prompt a name.
  • Create three input parameters.
    • Email
    • EmailSubject
    • Attachments
  • Select by Output JSON (preview) and click on Edit.
  • Add the following JSON code.
{
      "Order": "true"
}
  • Set the Model to either GPT 3.5 (cheaper but less accurate) or GPT 4 (more expensive and more accurate).
  • Set the Temperature to 0.
  • Set the Prompt as follows or make your own prompt.
  • Save the prompt.

Create a Power Automate Flow

The Power Automate flow will start for every incoming email and will send to the AI model, the email body, subject and names of the attachments. The model will return its determination in JSON form.

  • Create a new Power Automate flow with an outlook/email trigger, When a new email arrives in a shared mailbox.
  • Add an Initialize variable action to create a variable called All attachment names.
  • Add an Append to string variable and select by the name the All attachment names variable.
  • Set for the value the attachments of the email, with the following code. This will automatically add a Apply to each action.
items('Apply_to_each_-_Attachment')?['name'] - 
  • Add the Create text with GPT using a prompt action.
  • Select your created AI Prompt.
  • Set by attachments the variable All attachment names.
  • Set by Email the Body of the email.
  • Set by EmailSubject the Subject of the email.
  • This will start the AI model and it will return its results to the flow.
  • Form here on you can add in the requered steps for your specific process and test the process.