Showing posts with label Microsoft Flow. Show all posts
Showing posts with label Microsoft Flow. Show all posts

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.

Wednesday, 28 March 2018

Microsoft Flow : Custom response summary with user comments in Approval action

Flow approvals are really great to implement simple business processes. With the "Start an approval" action, we can carry out two kinds of approvals

1) Anyone from the assigned list
2) Everyone from the assigned list.

With the "Everyone from the assigned list", each of the assigned user is sent a request to approve or reject. Consider a scenario where you send a request to 2 users for approval. The first user approves however, the second user rejects the request. In this case, the final response of the approval step is "Rejected".

You might want to know which user approved and which rejected the request along with their feedback. There is a way to do that in Flow, by using the "Response Summary" value that comes with the output of the approval step.

Drawback :

With this value, comments of each user are not captured in the response summary.



















































Here, we can create our custom response which also includes the comments sent by the individual
user while approving or rejecting the request



If the response is rejected (or approved) based on where you want to configure the response summary


























- We loop the "Responses" value and for each response, we form a summary of the individual response using "IndividualApprovalData" compose action.

- Notice that the individual "Comments" are available now

- Response : We have used the "Approver response" value and not the "Response" value. Response value gives the overall response of the action.

- We have used a custom expression to format the date

             formatDateTime(items('Apply_to_each')?['requestDate'],'MM/dd/yyyy hh:mm:ss')
            formatDateTime(items('Apply_to_each')?['responseDate'],'MM/dd/yyyy hh:mm:ss')

- Leave some space at the bottom of each response in the compose action


- The "ResponseSummary" compose action joins all the individual responses using the below expression

Join(outputs('IndividualApprovalData'), '')

The custom summary looks as below





Monday, 30 October 2017

Work with Multi-value lookup fields in Microsoft Flow and SharePoint - Part 2

Part I of this post explains a couple of limitations of working with Microsoft Flow and SharePoint Multi-value lookup field.

Work with Multi-value lookup fields in Microsoft flow and SharePoint - Part 2

To overcome the challenge I decided to use SharePoint REST API to retrieve the field values. As you may already know, flow provides HTTP Trigger action which we can use to call the SharePoint REST API. The idea is to get an access token and retrieve the values through this HTTP trigger action. There are two great posts that helped me get an Access token, SharePoint scribblings and Shantha Kumar's blog

To start with, register an app in your SharePoint site through the "_layouts/15/AppRegNew.aspx" page. Provide the appropriate permissions so that it can access the multi-value lookup field data.

You'll have the client ID and client secret of the app. Also find out the TenantID of the tenant you are working on.

We create a new flow which is triggered when a new Item is created. Initialize the variables TenantID, ClientID, ClientSecret and a placeholder variable for AccessToken.








































Next, add a HTTP trigger action, to get the access token





























The body of this request is of the format

grant_type=client_credentials&client_id=<Client-ID>@<Tenant-ID>&client_secret=<Client-Secret>=&resource=00000003-0000-0ff1-ce00-000000000000/<tenantdomain>.sharepoint.com@<Tenant-ID>


Run the flow once till this step and see the history of the execution. Copy the body of the response. We will need it in the next steps.

Now we return to our flow and add a parse JSON action. Provide the "Content" as the body of the response from the previous HTTP trigger action. Use the body value copied in the previous step and paste it in the "Use sample payload to generate schema". This provides parse JSON action a sample format of the JSON that must be parsed.























Once this step executes, we are ready to use the access token. Next, use another HTTP trigger action to call SharePoint REST endpoint (here I have used a hard coded item ID) and retrieve the multi-value lookup field values. Along with the Title, you may also want to retrieve the ID of the looks. That might help you query other lists where these values may have been used.


































The results show the lookup values that were selected for the item.





















Now, we can then use these values as we would like to


Work with Multi-value lookup fields in Microsoft Flow and SharePoint - Part 1

I was recently working on a requirement to implement Microsoft Flow on a list that had a multi-value lookup field in it. The requirement was to fire a Flow when an item is created in the list and run a loop for each of the value selected in the multi-value lookup field.

At the time of writing this article, multi-value look-up fields are not supported in Microsoft Flow. This means that I could not straight away use the values from this multi-value look-up field and apply a loop.

If you would like to jump to how we can retrive the multi-value lookup column in Flow, here is the second part of the post

Work with Multi-value lookup fields in Microsoft flow and SharePoint - Part 2

The setup :

For this post, I am using a very simple setup, a "LookupRefList" with some 'Colours'  in it and another list "LookupUsedList" which has two fields which lookup data from "LookupRefList"

1) Colour : Single value lookup (just to show the difference in Flow values)
2) Colours : Multi-value lookup


























Flow with a single-value lookup field :

We can retrieve values from a single value lookup straight away

Flow setup :























Result :























Multi Value Lookup field : 

When we to fetch the multi-value column in Microsoft flow, the flow runs successfully, however, when you try to see the execution log, you see an error











































Click to see the log




















We cannot straight away use the multi-value look-up  in a apply to each loop.


























In the next part of the post, we retrieve multi-value lookup field values.

Work with Multi-value lookup fields in Microsoft flow and SharePoint - Part 2

Monday, 8 May 2017

Create a simple timer job for SharePoint online using Microsoft Flow

Creating scheduled jobs for SharePoint on-premise environment was pretty straight forward. Develop a timer job and deploy it to the farm and you are done. With SharePoint online, there are a few different ways to develop scheduled jobs, one of which is to create a Azure web job which talks to SharePoint data and runs the required tasks.

However, some organizations/small businesses do not have Azure subscription or the technical ability/developers to develop and deploy an Azure web job. Sometimes, the required functionality of the scheduled job is not too complex to create a Azure web job.

With Microsoft flow, we can easily create timer job-like features that run on a schedule and carry out a few simple tasks.I say simple because when I set out to explore several different scenarios where a Microsoft flow timer jobs can be used for a SP list, I found that Flow lacks several features. While it provides a lot of connectors, triggers, actions and conditions, as developers or power users there are a lot of actions/trigger/functionalities we need that are missing. At the end of this post I'll explain in brief about a scenario I tried to implement using Flow however it did not work out well.

Sample Timer Job : 

Meanwhile I decided to develop a simple timer job for asset request and procurement process. The job runs on a schedule and moves the "Approved" asset requests from requests list to a separate "Procurement" list. In this post we will see how to

1. Get items from SharePoint list
2. Filter SharePoint list items using a ODATA filter.
3. Loop on the list items
4. Create and delete list item

I have created two lists that will be used in this flow. Asset Request list with NEW and APPROVED requests (choice column) and a Asset Procurement list which will be empty initially.















Navigate to Flow from Office 365 and create a new flow from blank template.

















Give your flow a name. The first step we add here is a Schedule action. This will enable us to define a schedule for our process to run periodically.



















The schedule can be set based on Minutes/Hours/Days etc as given below
























Now, we will retrieve items from Asset Request list. Add a new action and select SharePoint























Select the Get items action




























Configure the Get items action. We retrieve the list items from Asset Request list and filter by only the items which are Approved



























Now that we have the approved items, the next step is to iterate through the items and create these items in the Asset Procurement list. To add the Loop operation, click "Add an apply to each" action as shown below


















We need to tell the loop action which data source it should iterate. Select the 'value' as indicated below. Notice the data source label is the previous action "Get items"



















We need to perform two actions now,

1. Create item in Asset Procurement list
2. Delete Approved items from the Asset request list

Add an action to create a list item in SharePoint.






























Select the site and list in which the items must be created and indicate the value for each column in target list. Notice that the data source from where we select the value for the item to be created is coming from our previous Get Items action. So the values coming from the Asset Request list will be added to the Asset procurement list.















































Now we create a new action to delete the Approved items from the Asset request list.


























We need to delete item from the Asset request list. So select the source carefully. Since we have retrieved items from the Asset request list through Get Items action, select the ID from that data source as shown below.





















The complete list flow look as shown below.








































After the flow execution, our lists look like :






































Limitated functionalities :

The limitation or issues mentioned here are something that I noticed at the time of writing this post. As and when updates are pushed to Microsoft Flow, I will try and update this post as well :)

While creating a SharePoint list item through flow, I noticed that we cannot add values to People column and Choice column as of now. There are a couple of more types of columns which are not supported.

https://powerusers.microsoft.com/t5/Building-Flows/Create-Item-Sharepoint-list-fields-missing/td-p/8930

Also, the SharePoint get items action only accepts Odata filter and does not support the Odata Select operation.

There might be several other actions/triggers which you may need to implement your business requirement but are not yet available in Flow.

Hope this helps !!