Monday 31 July 2023

PowerApps: Get the AppID dynamically in the current environment.

I came across one of the tasks in PowerApps to get the Canvas App ID dynamically.

AppID is a unique GUID assigned to a PowerApp. It changes from environment to environment and tenant to tenant.

In this blog, we will be learning how to set the default value in the Canvas app.

Please follow the below steps:

1. Sign in to Power Apps and choose the environment.

2. Select "Solutions" on the menu to the left.

3. Select the solution for which you'll create your app.

4. Select New > App > Canvas app.


5. Enter an App name and choose the layout for the app.

6. Click "Create" to create a blank canvas app.


7. Once created, the app opens in Power Apps Studio for you to start configuring the app's functionality.

8. In the left menu, select the "Data" option to open the "Data" pane.

9. Select Add data source. Search "Power Apps" and select "Power Apps for Makers".


10. Click "Add a connection" or use an existing connection.


11. Now a data source will be added to the app.


12. Add a new screen, "AppDetails_Screen" and add three Gallery controls with "Title, subtitle, and body" layout.

The screen will look like the one below.


13. In the Get All Apps Gallery control, set the Items property as below. It will return a table/list of records with all the Power App details in descending order based upon the created date and time.

PowerAppsforMakers.GetApps().value

The Get Apps method returns a list of apps. The return type will be an array ResourceArray[PowerApp]

Note: Returns all the apps to which the connection account has access across environments in a tenant.


Select the columns as below to get the "App Display Name", "Environment ID", "App ID".



Note: The GetApp method is used to get app details. It expects PowerApp Name [app: Name field of the PowerApp] as the first required parameter. This is not a friendly name/display name, but a GUID.


14. In the Get App by DisplayName Gallery control, set the Items property as below. It will filter the data based on the displayName property. It will return a table/list of record(s). Sorting is optional, as the details by default are in descending order based on the created date and time.

Sort(

    Filter(

        PowerAppsforMakers.GetApps().value,

        properties.displayName = "Hello Power App"

    ),

    properties.createdTime,

    SortOrder.Descending

)


It will return all the apps with the display name provided across all environments. In my case, it returned two records.

But the task is to get the Power App ID dynamically in the current environment. There is an environment name property on which we can add additional filters. In PowerApps, there is no direct way to get the current environment details. Fortunately, this can be achieved using a Power Automate flow.

15. Create a Power Automate flow by using steps.

a). Choose the Power Automate option in the left menu. Click the "Create new flow" button.


b). Click on the "Create from blank" button. A flow will be created with the default trigger.


c). Delete the flow trigger.


d). Add a new flow trigger, "PowerApps (V2)", a new version.


e). Add the "Compose" action.


f). Add expression to the compose action.

toLower(workflow()?['tags']['environmentName'])


g). Add the "Respond to a PowerApp or flow" action.


h). In this action, define the output fields you want to provide to PowerApps. Choose the type of output as Text.


i). Name the field, and select Add Dynamic Content to pass in data from the above compose action in the flow.


j). Click on the "Save" button to save the flow.


k). Now flow is added to the PowerApp.



16. App OnStart property calls the flow and sets the output of flow in a variable. It will be used later on.

Set(

    varEnvID,

    GetCurrentEnvironment.Run().result

)


17. In the Get App by DisplayName and EnvironmentName Gallery control, set the Items property as below. It will filter the data based on the displayName and environment name properties. It will only return a single record in a table/list.

First(

    Filter(

        (PowerAppsforMakers.GetApps()).value,

        (properties.displayName = "Hello Power App" And properties.environment.name = varEnvID)

    )

)


18. Now we will be discussing how to get the AppID and display it on a label. Add a new screen called "AppID_Screen" and add four labels like below.

In step 17, we can see the AppID (a GUID) value is present in the name property.

Now we will learn how to get it using the Lookup and Filter functions. Both will return the same data; only the syntax is different.

LookUp - Looks up a single record in a table based on one or more criteria.

Filter - Returns a filtered table based on one or more criteria.

Set the below value in the label "lbl_Lookup_Val".

LookUp(

    PowerAppsforMakers.GetApps().value,

    (properties.displayName = "Hello Power App" And properties.environment.name = varEnvID),

    name

)


Set the below value in the label "lbl_Filter_Val".

First(

    Filter(

        (PowerAppsforMakers.GetApps().value),

        (properties.displayName = "Hello Power App" And properties.environment.name = varEnvID)

    )

).name


19. As you can see in the below screen, the output of both functions is the same.



I Hope this will help all of you! 🧲
Please feel free to provide feedback.


🚀 "Happy Coding" 🚀

Friday 14 July 2023

PowerApps: Set the default user value in the Canvas app.

I came across one of the tasks in PowerApps to set the default value of the Person Type column.

In this blog, we will be learning how to set the default value in the Canvas app.

Please follow the below steps:

1. Create a new SharePoint list.

2. Create a Person/User type column called "Requestor Name".


3. Create a blank Canvas App with Format Tablet.

4. Add an Edit form control on screen and add the above created list as the data source for this form control. Set form DefaultMode to New.

5. For "Requestor Name DataCard" set the below value for the Default property.

Switch(
    frm_FileTransferService.Mode,
    FormMode.New,
    {
        '@odata.type': "#Microsoft.Azure.Connectors.SharePoint.SPListExpandedUser",
        DisplayName:User().FullName,
        Claims:"i:0#.f|membership|" & Lower(User().Email),
        Email:User().Email,
        Picture:User().Image
    },
    FormMode.View,
    ThisItem.'Requestor Name'
)


6. No need to do any changes in the Update property value. Its shown for reference only.


7. Under "Requestor Name DataCard" for DataCardValue.

    a. Comment on the Items property value, as it's not required. The items property is for populating the data in the people picker.


    b. Set the below value for the DisplayMode property. This DisplayMode property is used to configure whether the control inside the card allows user input (Edit), only displays data (View), or is disabled (Disabled).

If(
    frm_FileTransferService.Mode = FormMode.New,
    Parent.DisplayMode.Disabled,
    Parent.DisplayMode
)


9. Save and Publish the app.

10. Play/Run the app. In the New Form, the logged-in user is shown as default, and editing is disabled.



🚀 "Happy Coding" 🚀

Sunday 2 January 2022

Power Automate: Update file metadata and preserve version history.

In this blog, we will be updating file properties/metadata whenever a new file is uploaded into the library.

In this approach, we will use the REST API and wrap it into a Power Automate flow.

Create Flow

Complete flow with all actions


Flow URL - https://flow.microsoft.com/

1. Open the flow, click on the Create option, and select "Automated Cloud Flow".


Enter Flow name.
Choose the flow trigger as "When an item is created".
Click the Create button.



2. Enter the "Site Address" SharePoint site URL and the "List Name" library title where flow needs to be associated.

Add a new action step, "Compose" and rename it "Compose-user".

In input, add an object as shown below. Created By Claims is value; here we will get the claims value of the user who is uploading the file.



3. Add a new action step again, "Compose" and rename it as "Compose-update".

In input, add an object as shown below.

  {

    "FieldName": "Internal column name",

    "FieldValue": "desired value"

  },

  {

    ............

  },

  .....

]

The input value will be an array of objects, and each object defines the configuration of the column to be updated. The FieldName is the internal column name, and the FieldValue is the desired value that you want to set in that column.

In my example, the Editor (Modified by) and Title columns are updated.

In the Editor FieldValue output of Compose-user will be set.

Note: Flow is running under the service account. If the Editor field is updated, then we can also preserve the Modified By column. Otherwise, the service account value will be updated in the Modified By column.



4. Add a new action step: Send an HTTP request to SharePoint.

Here we will compose a REST API request call.

  • Site Address: SharePoint site URL where the library is present
  • Method: POST
  • Uri: _api/web/lists/getbytitle('<List Title>')/items(<ID>)/validateUpdateListItem
  • Body: 

{
   "formValues": outputs('Compose_-_update'),
   "bNewDocumentUpdate":true
}


        validateUpdateListItem: REST API ValidateUpdateListItem() function to update listitem metadata

        formValues: The value must be the output of the second Compose action.

        bNewDocumentUpdate: true (Not to create any version on update) or false (Create a version on the update)

        For details refer: https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj246412(v=office.15)



        Upload the file to the Documents library and test the flow.


        🚀 "Happy Coding" 🚀

        Saturday 24 July 2021

        SharePoint Home site.

         In this blog, we will be discussing the SharePoint Home site.


        What is SharePoint Home site?

        SharePoint Home site is a Communication site. It is the main landing/home site for your modern SharePoint intranet portal. It brings together news, documents, events, content, conversations, feeds, videos, and other resources.


        How to set the site as Home site?

        1. Create a new site or use an existing Communication site.

        2. Open SharePoint Online Management Shell in administrative mode and connect to SharePoint as a global admin or SharePoint admin.

        Here I have installed Microsoft.Online.SharePoint.PowerShell modules.

        SharePoint Online Management Shell: Getting Started

        3. Run the below command:

        Set-SPOHomeSite -HomeSiteUrl https://developer5.sharepoint.com/sites/TheLanding

        It will take some time to reflect on the change. In my case, it took 20 minutes. Run the below command to check which site is currently set as the Home site.

        Get-SPOHomeSite

        Home site can also be set easily through the SharePoint Online admin center.


        Go to SharePoint Online admin center at https://YourDomain-admin.sharepoint.com

        1. Click on the Settings option.

        2. Click on the "Home site" link.

        3. Enter the URL of the SharePoint Online communication site that you would like to set as a home site.

        4. Press the Save button.


        ~~~ Things to know ~~~

        1. Only PowerShell is available to set a site as the Home site. Currently, it cannot be done through UI as of now.

        Update: Home site can be set easily through the SharePoint Online admin center.

        2. Only one site can be set as the Home site for a Tenant.

        Update: In the latest release, users will be able to set up multiple home sites by using multiple Viva Connections experiences. The feature is currently in private preview and is expected to start rolling out broadly by the end of July 2023.

        3. Home site (Communication site) search scope will now be tenant-wide. The default search scope is at the site level only.



        4. Home site can be a Hub site also.

        5. News coming from the Home site will have a distinguishing highlighted Home site name banner.



        The same is available in the SharePoint mobile app.

        6. Enables quick access (Home icon) to the Home site from the SharePoint mobile app.


        7. The Global Navigation option will be enabled for the Home site now.


        Remove site as Home site

        Run the below command to remove the site as your Home site.

        Remove-SPOHomeSite
        Update: Home site can be removed easily through the SharePoint admin center.

        🚀 "Happy Coding" 🚀

        Sunday 4 July 2021

        SharePoint Online Management Shell: Getting Started

        In this blog, we will be discussing SharePoint Online Management Shell. The introduction, installation, and some example commands.


        Introduction

        SharePoint Online Management Shell is a tool that contains a Windows PowerShell module that allows administrators to manage their SharePoint Online subscription in Office 365 using PowerShell.

        SharePoint administrators can manage Sites, Users, Tenants and etc. Some of the tasks can be performed in the Microsoft 365 admin center, but not all operations are possible. Command-line operations in Windows PowerShell are composed of a series of commands. We can perform read, write, and execute command-line operations, and they are easier in PowerShell.


        Installation

        SharePoint Online Management Shell is not present out-of-the-box on the Windows operating system. You need to install the SharePoint Online Management Shell and connect to SharePoint Online.

        There are two options:

        1. Download and install the SharePoint Online Management Shell .msi package.


        2. Install the module from the PowerShell Gallery


        Open Windows PowerShell (or CMD) in administrative mode and install the SharePoint Online Management Shell by running the below command:

        Install-Module -Name Microsoft.Online.SharePoint.PowerShell
        

        Once the module is installed, execute the below command in administrative mode to check its details:
        Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version
        

        To update the SharePoint Online Management Shell, run the below command in administrative mode:
        Update-Module -Name Microsoft.Online.SharePoint.PowerShell
        

        To uninstall the SharePoint Online Management Shell, run the below command in administrative mode:
        Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell
        


        Run the below command to connect with the SharePoint Online admin center. Enter the SharePoint admin account credentials in the request dialogue box.

        Connect-SPOService -Url https://developer5-admin.sharepoint.com
        




        To disconnect and close the connection, run the below command:

        Disconnect-SPOService -Url https://developer5-admin.sharepoint.com


        🚀 "Happy Coding" 🚀