Showing posts with label SPFx. Show all posts
Showing posts with label SPFx. Show all posts

Tuesday, 18 September 2018

Copy SharePoint modern site page along with content

Being able to copy a modern site page along with the content and layout enables us to use page templates in a SharePoint modern site. In a scenario where we want to create multiple site pages with a defined template, this functionality comes very handy. For instance, you can create a news page with all the sections and required web parts laid out on it and treat it as a page template to be used to create pages on demand.

For testing purpose, I placed a few web parts on the page template to see if they get copied over correctly and the following web parts worked well. You can try the functionality with other web parts to see if it fits your requirement.

  • Custom SPFx webpart
  • Recent Documents
  • People
  • Quick Links
  • Text
  • Embed
  • Bing Maps

Copying works within the site and also to a different site. When copying a page with custom SPFx web part to a different site, the web part solution must be installed on the target site.

Here is the sample code. It extracts the HTML content and title from the source page and adds the content to the "CanvasContent1" field of the target page. The Code uses PnP Core library - "SharePointPnPCoreOnline" nuget package.

Replace the placeholders in the code below.



Friday, 10 August 2018

Bulk upgrade SPFx solution in multiple site collections using Microsoft Flow

I was recently working on an assignment where we set up an automated Site Collection provisioning process and developed several SPFx webparts. Each of the newly provisioned site collection would have these SPFx web parts provisioned on the pages of the site.

In the web part development process, we re-deployed the solution several times after the initial deployment. This was for the two scenarios below.



Changes made to the already deployed web parts :


When changes are made to the existing web parts which are already deployed to Site collection pages, the process of making updates available to these web parts is easy. Just update the SPPKG file in the App Catalog and replace the web part bundle files with the new build. Once this is done, the web parts in all the sites where the solution is deployed would get the updated functionality


New webparts added to the solution : 


If you have added new web parts to your SPFx project since the last release, the above process won't make these web parts available in the site collections where the solution was already installed.
In this case, we need to 

  • Increment the solution package version number
  • Redeploy the SPPKG file to App Catalog 
  • Update the web part bundle files in the CDN location 
  • UPGRADE the solution in the site collections.


When we have tens or hundereds of site collections where we need to upgrade the solution, manual upgrade is definitely not an option. We can automate this with a PnP PowerShell script using the "Update-PnPApp" command. 


https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/update-pnpapp?view=sharepoint-ps

In our case, the list of all the provisioned site collections was available in a SharePoint list column (part of provisioning process where users request for new site.)

Microsoft Flow came to the rescue - Read all the list items and for each site in the list, execute a REST API call using the "Send an HTTP request to SharePoint" action.


ALM API Endpoint to upgrade the solution is (https://docs.microsoft.com/en-us/sharepoint/dev/apis/alm-api-for-spfx-add-ins)

"_api/web/tenantappcatalog/AvailableApps/GetById('<GUID>')/Upgrade"

The GUID of the solution can be found using the PnP PowerShell Command. Connect to a site collection and run the command : Get-PnPApp
































Fast and easy !! Hope this helps.