Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

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" 🚀

        Tuesday 19 November 2019

        Export PDF in Power Apps and Power Automate (MS Flows): Approach 1

        In this blog, we will be exporting the List Item details into the PDF document with a button click. This approach is based on the use of both PowerApps and PowerAutomate.

        In this scenario, a customized PowerApps form is there that is used to display data coming from the SharePoint list, and a button will be present on click of which users can export content into the PDF.

        Create Flow

        Complete flow with all actions


        1. Open the flow, click on the Create option, search for "PowerApps", and select the option "PowerApps button" which triggers the flow on button click.


        2. Add the "Initialize variable" action.
        Enter the required values: – Name, Type and Value. To initialize the value, click on "See more".

        Now click on the option "Ask in PowerApps"; it means the value will come from PowerApps form when flow is called as a parameter.

        Select and add the initialized values. Similarly, create a new variable. Filename and initialize.

        Now create the FileFullname variable. To initialize the value, select the Expression tab and concatenate the value of the filename variable with the .html file extension.

        Similarly, create a new variable, CurrentUser and initialize.

        3. Add "Create File" (OneDrive for Business) action.
        Click on the Folder icon present in the Folder Path textbox. Browse the library and select the folder under which the HTML file will be saved and later converted to PDF.

        Set the variables initialized above for File Name and File Content.

        4. Add the "Create file using path" (OneDrive for Business) action.
        Click inside the File Path textbox, and a callout will open. Select Path value from the Create file in OneDrive group under Dynamic content. Set PDF as the Target type.
        Note: Create file OneDrive is the previous action, and these are all the outputs of it.

        5. Add the "Send an email (V2)" (Office 365 Outlook) action.
        Provide the required value for this as shown below.


        Modify PowerApps Form

        1. Open the list where Export PDF functionality needs to be implemented. Click on "Customize forms" to open PowerApps.

        2. Add a new screen and add an HTML text control to it.

        3. Add the HTML content with dynamic values as shown. The content will be added in double quotes.


        4. Add a button for "Export to PDF" functionality. On the button, attach the flow.
            a. Select the button.
            b. On the Action tab, select Flows.
            c. All available flows will appear; select the required one.
            d. Choose the "OnSelect" option to RUN the flow and pass the required parameters.
            e. Save and Publish the PowerApps.

        5. Open the display form and click on the "Export PDF" button.

        6. The exported PDF will be sent to the current logged-in user's email..

        Check the final exported PDF here


        🚀 "Happy Coding" 🚀

        Tuesday 20 March 2018

        Enable Anonymous access to search results.

        I am working on one task to display list items using a display template to anonymous users. I have also made the managed search property safe for the anonymous user, but it is still not working for the anonymous user.

        Out-of-the-box, the search results webpart (via display template) will try to display data to users (anonymous and authenticated users); authenticated users will see results, while anonymous users will see no results.

        Here I will use the PowerShell script to allow list-level anonymous access.



        The commented AnonymousPermMask property, according to MSDN, is deprecated and you need to use AnonymousPermMask64.



        Instead of ViewFormPages, we need to use AnonymousSearchAccessList, which is described as "Make content of a list or document library retrieveable for anonymous users through SharePoint search. The list permissions in the site do not change".

        Then run a full search crawl.


        🚀 "Happy Coding" 🚀

        Sunday 7 May 2017

        SharePoint search query length error.

        SharePoint 2013 search results query works properly if select, filter, and other options are in the search query text limit. If the search query limit exceeds the search results, it gives an error.

        "An administrator configuration transformed your query into an invalid query"


        The search length (in KB) is controlled by the property MaxKeywordQueryTextLength of the SharePoint search service application. The default "MaxKeywordQueryTextLength" value is 4096 (4 KB). Use the PowerShell commands given below.




        So increasing the MaxKeywordQueryTextLength value from 4 KB to 8 KB helped in fixing the error.

        The reference blog: https://blogs.msdn.microsoft.com/sridhara/2014/05/06/sharepoint-2013-searchserviceexception-the-maximum-allowed-value-is-4096/


        🚀 "Happy Coding" 🚀

        Sunday 20 November 2016

        SharePoint 2013 Apps Environment Configuration.

        Setting up a SharePoint development environment has always been challenging, and with the new Apps model in SharePoint 2013, there are even more options and requirements.


        First, setup and configure DNS on a Windows server. (http://www.tomsitpro.com/articles/configure-dns-windows-server-2012,2-793.html)

        The steps to configure the SharePoint 2013 apps environment.

        a) Create Apps Forward Lookup Zone

        SharePoint 2013 Apps have their own isolated URLs, which are separate from the URLs of the sites where the app is being deployed and where the app is being used. In order to provide isolation, apps should run in their own domain instead of in the same domain name as your farm. Using a different domain name for apps helps prevent cross-site scripting between apps and SharePoint sites.

        Microsoft recommends that the new domain name should NOT be a subdomain of the domain that hosts the SharePoint sites.

        1. Open DNS Manager and run it as an administrator from the Start screen.

        2. In DNS Manager, right-click Forward Lookup Zones, then the New Zone context menu option.



        3. Click Next on the New Zone Wizard dialogue box.

        4. On the Zone Type step, select the Primary Zone and click the Next button.

        5. On the Zone Name step, enter the app domain name (like spappsdeveloper.com), and click the Next button.



        6. On the Dynamic Update step, select the type of dynamic updates you want to allow. Here, with the Allow both nonsecure and secure dynamic updates option selected, click the Next button.





        b) Link the SharePoint App Domain to the SharePoint Server

        Now DNS will forward all the requests from spappsdeveloper.com to the SharePoint server hosting the apps.

        1. In DNS Manager, under Forward Lookup Zones, right-click the newly created zone or app domain (spappsdeveloper.com). Click New Alias (CNAME) from the context menu option.

        2. On the New Resource Record dialogue, enter * as the Alias name.

        3. For a Fully qualified domain name (FQDN) for target host box, select the Browse button.

        4. On the Browse dialogue, select server > Forward Lookup Zones > SharePoint sites host domain > select the record that points to the server that hosts the SharePoint site. Ensure Hosts and Aliases (A and CNAME Records) is selected as the Record types, and click the OK button.

        5. Click OK to close the dialogue box.


        c) Creating the Subscription Settings and App

         Management Service Applications

        1. In SharePoint Central Administration, click the Manage service applications option.

        2. Click the New button, then the App Management Service menu item.

        3. On the New App Management Service Application dialogue, enter “App Management Service” as the Service Application Name. Select the Use existing application pool option, and then select AppManagementService Pool from the drop-down. Ensure the Create App Management Service Application checkbox is checked. Click the OK button.

        4. Or you can use the PowerShell command to create an App Management Service Application.

        # get the service application pool
        $serviceAppPool = Get-SPServiceApplicationPool -Identity "AppManagementService Pool"

        # create app management service application and save its response in variable
        $appMngmntSvc = New-SPAppManagementServiceApplication -ApplicationPool
        $serviceAppPool -Name "App Management Service" -DatabaseName "App Management Service DB"

        # create app management service application proxy and mapping it to service application
        New-SPAppManagementServiceApplicationProxy -ServiceApplication $appMngmntSvc

        5. Once returned to the list of service applications, ensure both App Management Service Applications are started.

        6. Open the SharePoint 2013 Management Shell as an administrator and run.

        7. Start the SPAdminV4 and SPTimerV4 service applications.

        net start SPAdminV4

        net start SPTimerV4

        8. Set the domain used to host apps to the new zone created above. It can be set by PowerShell as "done" or via central administration. It can also be done later at the Configure App URL step (see below).

        # App Domain Name.
        Set-SPAppDomain "spappsdeveloper.com"


        9. Start the AppManagementServiceInstance and SPSubscriptionSettingsServiceInstance service instances.

        # Start the App Management & Subscription SharePoint services.
        Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance"} | Start-SPServiceInstance


        10. Ensure the AppManagementServiceInstance and SPSubscriptionSettingsServiceInstance service instances are Online.

        # Check the "Online" status of the App Management & Subscription SharePoint services.
        Get-SPServiceInstance | where{$_.GetType().Name -eq "AppManagementServiceInstance" -or $_.GetType().Name -eq "SPSubscriptionSettingsServiceInstance" }


        11. Create the SharePoint Subscription Service.

        # get the service application pool
        $account = Get-SPManagedAccount "WIN-EODPTE6TSSE\sppool"
        $serviceAppPool = New-SPServiceApplicationPool -Name "SettingsServiceAppPool" -Account $account

        $serviceAppPool = Get-SPServiceApplicationPool -Identity "AppManagementService Pool"

        # create subscription settings service application and save its response in variable
        $appSubSvc = New-SPSubscriptionSettingsServiceApplication –ApplicationPool
        $appPoolSubSvc -Name "SettingsServiceApp" –DatabaseName "SPSubscriptionSettingsServiceDB"

        # create subscription settings service application proxy and mapping it to service application
        $proxySubSvc = New-SPSubscriptionSettingsServiceApplicationProxy –ServiceApplication $appSubSvc




        d) Configure the App URL

        Set the name for the site subscription.

        1. Open Central Administration, click Apps, and then click Configure App URLs.

        2. In the App Prefix box, type a name to use for the URL prefix for apps.

        3. Or it can also be done by PowerShell.

        # SharePoint App Subscription name.
        Set-SPAppSiteSubscriptionName -Name "apps" -Confirm:$false



        Create a new Developer Site site collection for local App deployment.
        Now you're ready to deploy your SharePoint apps to your local SharePoint development environment.

        I hope this will help; do write your comments and suggestions.


        🚀 "Happy Coding" 🚀