Showing posts with label Power Platform Consulting. Show all posts
Showing posts with label Power Platform Consulting. Show all posts

May 22, 2025

Step-by-Step Guide: Create a PCF Control to Record Video in Power Apps

Introduction

In Power Apps, the default controls are often enough for typical business needs, but what if you need a more customized user interface or logic that goes beyond the built-in features? That’s where the PowerApps Component Framework (PCF) comes into play.

PCF enables developers to create custom components using modern web technologies like HTML, CSS, and TypeScript. These components can be reused just like standard Power Apps controls but offer much greater flexibility and power.
 
With PCF, you can build: 

  • Rich visual components like sliders, charts, or custom input fields
  • Controls that connect to external data sources
  • Reusable UI elements across different apps and environments

Whether you're enhancing user experience or integrating third-party libraries, PCF gives you the tools to take your apps beyond low-code.

In this blog, we’ll walk you through creating a custom PCF control that records video directly within a Power Apps, perfect for scenarios like field service reporting.
 
Prerequisites
Before you begin, ensure you have the following tools and knowledge:
  • Node.js (LTS version)
  • Power Platform CLI (pac)
  • Visual Studio Code
  • A Microsoft Power Apps Developer Environment

Use Case: Record Video in Power Apps
Imagine a field engineer needing to quickly document a machine fault. Instead of recording a video externally and uploading it later, a custom PCF control enables the engineer to record and save the video directly within the mobile app, streamlining the entire submission process.


Step-by-Step Guide to Creating the PCF Control

1. Create the PCF Control

  • Open Visual Studio Code and run:

pac pcf init --namespace VideoRecoder --name VideoRecoder --template field 

  • Then install the dependencies:

 npm install

 2.  Add Video Recording Logic (in index.ts)

  • Use the MediaRecorder API to access the camera and record video.

private async startRecording(): Promise<void> {
        this._errorElement.innerText = "";
        try {
            // Request back camera with facingMode: "environment"
            const stream = await navigator.mediaDevices.getUserMedia({
                video: { facingMode: "environment" },
                audio: true
            });
            this._videoElement.srcObject = stream;
            this._videoElement.play();

            this._mediaRecorder = new MediaRecorder(stream);
            this._recordedChunks = [];

            this._mediaRecorder.ondataavailable = (event) => {
                if (event.data.size > 0) {
                    this._recordedChunks.push(event.data);
                }
            };

            this._mediaRecorder.start();
            this._startButton.disabled = true;
            this._stopButton.disabled = false;
            this._uploadButton.disabled = true;
        } catch (error) {
            this._errorElement.innerText = "Failed to access camera/microphone. Please
ensure permissions are granted.";
            console.error("Recording error:", error);
        }
    }

    private stopRecording(): void {
        if (this._mediaRecorder && this._mediaRecorder.state !== "inactive") {
            this._mediaRecorder.stop();
            this._videoElement.srcObject = null;
            this._startButton.disabled = false;
            this._stopButton.disabled = true;
            this._uploadButton.disabled = false; // Enable upload button after stopping
        }
        console.log("from stopRecording() test");
    }


You can view the complete source code here.
  • Run the development server to test locally:
npm start

3. Build the PCF Control into a Solution
  • Create a new solution folder and initialize it:
mkdir VideoRecoderSolution
cd VideoRecoderSolution
pac solution init --publisher-name YourPublisher --publisher-prefix yourprefix
Then add the reference and build:
pac solution add-reference --path ..\..\
dotnet build
  • A .zip file will be created inside VideoRecoderSolution > bin > Debug

4. Import the Solution into Power Apps

  • Open your Power Apps portal
  • Navigate to Solutions

  • Click Import Solution and select the generated .zip file


  • Click Next > Import
Once imported
  • Go to your app
  • Click Insert > Get More Components

  • Click on code and select your custom component
  • Click Import, and it will be available under Code Components


Conclusion

With PCF, you unlock a whole new level of customization in Power Apps. In this tutorial, we created a practical video recording control - ideal for industries like field services, insurance, or any scenario where direct media input is valuable.


If you have any questions you can reach out our SharePoint Consulting team here.

September 29, 2022

Get Members from the Security Group in Power Apps

We often come across a requirement wherein we need to fetch the information from the Security Group and need to display within Power Apps for Business Logic implementation.

Example:
Below is one of the Security Group created in Microsoft 365. Here, there are two members added to that Security Group.

In Power Apps, we need information about those two users.

Step 1: Open Power Apps Canvas App. First, we need to add Office 365 Groups Connector. For that, 
  1. Go to View Menu, and select Data sources.

  2. Search for “Office 365 Groups”. Select the highlighted one and add a connector to the App.

  3. Once the Connector is added, this will look like this.

Step 2:
  1. Open Power Apps screen and add a button.
  2. Write the following line of code for “On Select” event of the button.
     ClearCollect(MembersfromSG,Office365Groups.ListGroupMembers("GroupID").value)  
  3. Here, MembersfromSG is the Name of the collection. Office365Groups.ListGroupMembers(“Group ID”) returns the information about all the members of that security group.

How can we find that Group ID for the Security Group?
  1. Open Azure Portal and search for Groups. This will open the following screen.
  2. Select your security group for more information.
  3. Copy Object Id. This is the Group ID. We can use this Group ID in the below formula. The formula will look like this.
 ClearCollect(MembersfromSG,Office365Groups.ListGroupMembers("xxxxxxxx-1xxb-4x4b-xxxxxx").value)  

Step 3: Now, add Gallery Control and add Collection as a data source. This will show users in the Gallery.

Step 4: Now, let’s run the solution. This will show, User’s Display Name and User Principal Name.
You can check more properties of members returned by this collection from the executed collection.

Conclusion:
This is how we can get the Member Information using Office 365 Groups Connector in Power Apps.

If you have any questions you can reach out our SharePoint Consulting team here.

July 14, 2022

Close and Logout Power Apps using Exit() Function in Power Apps

Overview:

Sometimes, there is a requirement, wherein we need to close our Power Apps and Logout the user from the App’s context. How can we achieve this requirement? 

Power Apps provide one Power Fx formula to achieve this which is the EXIT() function! So, now Let’s explore this feature in detail!!

We have created one Power Apps with two buttons. First, let’s check the syntax!

Syntax: Exit([Signout]) 
  • Here Signout is an optional parameter that accepts a Boolean value. 
  • If we pass true, then, it exits from the app and signs out the user!

Let’s get started!

Step 1:

Add button and add the following code without optional parameter.

Step 2:

Add button and pass signout parameter as true. 

This will log out to the end-user and prompt them to Sign In again!

Conclusion:

Hope, this small Power Apps trick helps you!!

If you have any questions you can reach out our SharePoint Consulting team here.

September 23, 2021

Introducing Co-Presence in Power Automate

Overview

Microsoft recently rolled out a prominent feature which is “Co-Presence” functionality in Power Automate. Most of the time, when we are working with multiple developers on the same Flow, we are unaware of who is editing the Flow? With this new feature, now we can track all the persons who are editing the Flow in real-time. 

If multiple users make changes to the flow simultaneously, Power Automate detects conflicts during the Flow save operation and presents appropriate options to the user to minimize conflicts. So, let’s get started!

Step 1:

We have one Power Automate Flow which is shared with Dhruvin and Shriraj.


Step 2:

Dhruvin and Shriraj both have opened the Flow in Edit Mode.

Step 3:

Dhruvin can see Shriraj’s avatar as “Co-Presence”.

Step 4:

Now, let’s make some changes with Shriraj’s account and Save the Flow. The changes will be saved!

Step 5:

Let’s make some changes to Dhruvin’s account. 

Try to save the changes. This will pop up with the following screen.

Now, let’s try to understand the options provided here!
  • Discard your changes: This will discard Dhruvin’s changes and keep Shriraj’s changes as is.
  • Save a copy of your changes: This will save a Copy of my changes as a separate flow and appear in My Flow section.
  • Overwrite other people’s changes: This will keep Dhruvin’s changes and discard Shriraj’s changes.

Conclusion:

This is how the Co-Presence feature will work in Power Automate. Isn’t that cool? Happy Automation!!!

If you have any questions you can reach out our SharePoint Consulting team here.

September 16, 2021

Power Apps Validation Tip - End Date and time should be greater than Start Date and time

Overview:

We implemented several Power Apps forms for a consulting firm based out of Alpharetta, Georgia, United States. We came across a scenario to validate Start Date & End Date in one of the forms. In this article, we will talk about how we can apply DateTime validation in our Power Apps Form. Most of the time, we need to implement, one most common validation in Power Apps where End DateTime must be greater than Start DateTime. How can we apply that validation? Let’s see!

We have the following form in our Power Apps. We want to validate, check-out time should be greater than check-in time! So, how can we achieve this?


Step 1:

Please check the Datacard for Check-In and Check-Out time.

Step 2:

Add the following line of code on below highlighted controls! Need to add the same code on all following controls!

 If(  
   Or(  
     IsBlank(  
       DateValue2.SelectedDate + Time(  
         Value(HourValue2.Selected.Value),  
         Value(MinuteValue2.Selected.Value),  
         0  
       )  
     ),  
     IsBlank(  
       DateValue1.SelectedDate + Time(  
         Value(HourValue1.Selected.Value),  
         Value(MinuteValue1.Selected.Value),  
         0  
       )  
     )  
   ),  
   Set(  
     IsEndDateValid,  
     true  
   ),  
   DateDiff(  
     DateValue1.SelectedDate + Time(  
       Value(HourValue1.Selected.Value),  
       Value(MinuteValue1.Selected.Value),  
       0  
     ),  
     DateValue2.SelectedDate + Time(  
       Value(HourValue2.Selected.Value),  
       Value(MinuteValue2.Selected.Value),  
       0  
     ),  
     Minutes  
   ) > 0,  
   Set(  
     IsEndDateValid,  
     true  
   ),  
   Set(  
     IsEndDateValid,  
     false  
   )  
 )  

Step 3:

Set Validation message
 If(!IsEndDateValid, "Ënd Date Time should be greater than Start Date Time")  

Step 4:

Set Visible property for an Error message.

Step 5:

Prevent form for submitting an invalid entry by setting up the below condition for “OnSave”. If you are using a standalone Canvas app, then you need to write the same code on your button click!

Step 6:

Change "OnNew" Property of form. If you are using a standalone Canvas app, then you need to write the same code on the New button of the form!
 NewForm(SharePointForm1);Set(IsEndDateValid,true)  

Step 7:

Save and Publish form!

Conclusion:

This is how we can simply apply end DateTime validation for Power Apps! Happy Power Apping!

If you have any questions you can reach out our SharePoint Consulting team here.

February 18, 2021

Update SharePoint Hyperlink fields with URL and Description using Power Automate (MS Flow)

Introduction

We recently implemented an automated approval process in SharePoint Online using Power Automate for the HR department of an Engineering Company based out of Denmark. We came across a scenario wherein it was required to update the value of the Hyperlink field in the SharePoint list with URL & Description from Power Automate.

Problem Statement

We cannot directly update the value of the Hyperlink field with description from using "Update Item" action in Power Automate (MS Flow). So in this article, we will see how to update the value of the Hyperlink field with URL & Description using HTTP Request Action in Power Automate.

Resolution

As an alternate, we can use "Send an HTTP request to SharePoint" action in Power Automate to update the value of the Hyperlink field with URL & Description in SharePoint. Let's see the step by step process to perform the same, for easier understanding we will go with an example SharePoint List with a straightforward scenario.

SharePoint List

We have already created a SharePopint List with two fields Title (Single Line of Text) and Address (Hyperlink).


Steps to Follow

Step 1: Open your flow and add "When an item is created" trigger and provide your "Site Address" and "List Name".


Step 2: Add a new action "Send an HTTP request to SharePoint".



Step 3: Once successfully added, provide all the details as required.


Site Address: Your Site Address

Method: POST

Uri :  _api/web/lists/GetByTitle(‘ListName’)/items([ID]). (Update “ListName” to your list’s name & replace “[ID]” with the ID field from dynamic content).

 

Step 4: Click on “Text Mode” in "Send an HTTP request to SharePoint" action.



Step 5:  Add the below code in the Header Textbox.
1:  {  
2:  "Content-Type": "application/json;odata=verbose",  
3:  "X-HTTP-Method": "MERGE",  
4:  "IF-MATCH": "*"  
5:  }


Step 6:  Add the below code in Body Textbox

1:  {'__metadata': {'type':'SP.Data.RecordsListItem'},  
2:  'Address':{'Description': 'Click Here','Url': 'https://www.msn.com'}  
3:  }  


Step 7: Replace 'SP.Data.RecordsListItem’ with ListItemEntityTypeFullName of the list. We can use "<Site URL>/_api/web/lists/GetByTitle('<List Name>')?select=ListItemEntityTypeFullName" endpoint to know ListItemEntityTypeFullName for a specific SharePoint List.

Step 8: Replace 'Address' with the name of your  hyperlink column name

Step 9: Replace 'Description' text with the label/description text you want for the link

Step 10: Replace https://www.msn.com with your hyperlink.


Output

When a new item is created in the SharePoint List, the Hyperlink Field value gets populated with Description from Power Automate (with values configured in Power Automate).


Hope this helps!

If you have any questions you can reach out our SharePoint Consulting team here.

February 11, 2021

Exploring Microsoft Teams connector in Power Apps – Get Channel Messages

Introduction:

We recently implemented Power Apps - Canvas App that was having the integration with Microsoft Teams for Construction & Engineering company based out of Washington, United States. One of the requirements was to get the MS Teams - Channel Messages and display the same in Power Apps.

In this article, we will explore the Microsoft Teams connector available in Power Apps. The Teams connector with Power Apps opened lots of possibilities to leverage Teams capability within the Power Apps. Let's check how to get messages of a specific channel in MS Teams in PowerApps and what other actions are available using the Teams connector.

Business Scenario:

Here, first we will show all available Teams for the current logged in user. When user clicks on Teams name, this will open all channels for the current Team. Once we click on the channel name, we will be able to see all the messages from that channel on the right side section. That’s the end goal we will achieve at the end of the blog. So, now let’s get started!



Step 1: Add "MicrosoftTeams" connector in Power Apps from DataSource.

Step 2: Insert a Blank Gallery and add the below code in the Items of the Gallery.

 MicrosoftTeams.GetAllTeams().value  

Step 3: Add a label in the Gallery and show the DisplayName of the Items.

 ThisItem.displayName  

 Hence, you can see it will list all the teams that you are part of.


Step 4: Now we require all the channels of the selected Team. For that, insert another gallery and add this code into the Items of that Gallery.

MicrosoftTeams.GetChannelsForGroup(Gallery1.Selected.id).value 

Step 5: Now as we have both the Items (i.e. Team and Channel), we can get the messages of that specific selected channel. Insert a new Gallery and add this code in the Items property of that Gallery.

 SortByColumns(MicrosoftTeams.GetMessagesFromChannel(TeamsGallery.Selected.id,  
 ChannelGallery.Selected.id).value,"createdDateTime",Ascending)  

Step 6: Add a HtmlText in this Gallery and place the below code in the HtmlText

 ThisItem.body.content  

As the message which is returned is in the form of HTML, we need to use the HtmlText element for displaying messages. The final output may look something like shown in the below image:


Here are some of the properties which we can show along with the channel messages:

         From

         User

         ThisItem.from.user.displayName

         ThisItem.from.user.id

         Device

         ThisItem.from.device

         Attachments

         ThisItem.attachments

         Mentions

         ThisItem.mentions

         Reactions

         ThisItem.reactions

         Dates

         ThisItem.createdDateTime

         ThisItem.lastModifiedDateTime

         Importance

         ThisItem.importance

As a final outcome, we are able to generate the screen like below.

References:

Please check the following link to get more information about different available methods for Microsoft Teams connector for Power Apps.

https://docs.microsoft.com/en-us/connectors/teams/#actions

Conclusion:

This is how we can use the Microsoft Teams connector for fetching Channel messages in Power Apps. Happy Power Apping!

If you have any questions you can reach out our SharePoint Consulting team here.

February 4, 2021

How to Run Power Automate with Admin Consent from Power Apps?

Introduction

We recently converted the InfoPath forms to Power Apps forms for an Engineering & Construction company located in Boston, Massachusetts, United States. In one of the forms we converted, the requirement was to populate a dropdown list with the members of a SharePoint Group as values. 

Problem Statement

To populate a dropdown in Power Apps with SharePoint group users, we added Microsoft Power Automate to our Power Apps application with “Send an HTTP request to SharePoint” action. But when a user who is not a part of the group nor has Full Control permission opens the form, the flow would fail. 

Error in Power Apps:


Error in Power Automate (MS Flow): 

Error: Access denied. You do not have permission to perform this action or access this resource.

Root Cause:

Flows started by Power Apps run in the context of the user who is running the Power Apps. So the problem occurs when a user who is not a part of the SharePoint Group nor has Full Control permission opens the form. In this case, the flow would fail.
  

Resolution

So we decided to run the flow in the context of SharePoint Add-ins. When the add-in-only policy is used, SharePoint checks only the permissions of the add-in principal. Authorization checks succeed only if the current add-in has sufficient permissions to perform the action in question, regardless of the permissions of the current user (if any).
The entire procedure covers the following steps:
  1. Register SharePoint Add-ins 
  2. Create Power Automate flow to get users from SharePoint Group
  3. Configure flow in PowerApps

Step-1: Register SharePoint Add-ins
Please check This Article which describes the steps to register App in SharePoint. Client ID and Client Secret availed from this process will be used in Step 2.
 
Step-2: Microsoft Flow to get SharePoint Users
  1. Create an instant cloud flow with Power Apps trigger as shown in the below picture.

  2. Now, instead of “Send an HTTP request to SharePoint” action we will be using “HTTP” action.

    In the HTTP action fill the details as per below:
    • Method: Post
    • Replace the Tenant ID in the URI.
      URI: https://accounts.accesscontrol.windows.net/TenantID/tokens/OAuth/2
    • Replace the highlighted content in the body.
      Body: grant_type=client_credentials&client_id=ClientID@TenantID&client_secret=ClientSecret&resource=00000003-0000-0ff1-ce00-000000000000/TenantName.sharepoint.com@TenantID
    • Headers:
      Key: Content-Type
      Value: application/x-www-form-urlencoded

  3. Now in the next step, we will use Compose action. Pass the access token that we get from the HTTP action in the inputs.Formula: body(‘HTTP’)[‘access_token’]

  4. In the next step, we will again use the HTTP action.

  5. In the HTTP 2 action fill the details as per below:
    • Method: Get
    • Replace the highlighted content in URI. Set the group name to the SharePoint Group of which you want the users.
      URI: https://tenantname.sharepoint.com/sites/sitename/_api/web/sitegroups/getbyname('GroupName')/users
      • Headers:
        Key: Accept; Value: application/json;odata=verbose
        Key: Authorization; Value: Bearer and the output of compose action as shown in the above image. 

      1. Now we will use the Select action to get only the specific properties from all the elements of the array and form a new array as shown in the below picture.
        • Pass the results of “HTTP 2” action in the From as body('HTTP 2')['d']['results'].
        • We need to map the properties to make the array format as required in Power Apps. You can check the properties from the json generated in the HTTP 2 action. Pass the keys as shown in the image and values as item()?['PropertyName'].



      2. The last step of the Flow is Response action. Here we pass the output of the Select Action.

      3. Click on Show advance option and select Generate from sample. Here, we need to insert a sample JSON payload. Add the following JSON structure:
         [  
          {  
           "Email": "",  
           "Claims": "",  
           "DisplayName": "",  
           "Department": "",  
           "JobTitle": "",  
           "Picture": ""  
          }  
         ]  
        

      Step-3: Configure the Flow in Power Apps
      1. Now we will store the response generated by the flow in a collection by passing ClearCollect(CollectionName,'FlowName'.Run()); on the “OnVisible” property of the “FormScreen”.

      2. Pass the collection on the “Items” property of the DataCardValue as shown in the below picture.

      Conclusion

      This is how we can call our Power Automate flow with admin consent from PowerApps.

      If you have any questions you can reach out to our SharePoint Consulting team here.