Showing posts with label Office365. Show all posts
Showing posts with label Office365. Show all posts

June 10, 2021

How to implement SharePoint CRUD Operation using Power Automate?

Introduction

In this article, we will talk about how we can Create, Update and Delete data using “Send an HTTP request to SharePoint” Action in Power Automate. 

Real-Life Business Use Case:

We all know with OOTB Power Automate action - “Send an HTTP request to SharePoint” we can perform SharePoint CRUD operations easily. However, sometimes, there are situations where we need to set up one flow for a different site. For this scenario, we need to pass Site URL and List Name Dynamically. At that time, we can use OOTB Power Automate action - “Send an HTTP request to SharePoint” and pass Site Name and List Name dynamically. In this article, we will see the most used methods, such as GET, POST, PATCH, and DELETE with examples.

Prerequisites:

Log in to the flow portal with your Office 365 credentials.
For this article, we have created two SharePoint List. One is for Training and the second List for PostData

Overall Architecture/Schema of Lists:

Below is the column structure of the Training List.
 
Below is the column structure of the PostData List.
 
Now, let’s get started with development procedure!

Step 1:

Add Manual Trigger. We can choose trigger based on business need.

Step 2: 

Initialize variables for site URL and list name.

Step 3: Get Items

Click on New Step and add an action “Send an HTTP request to SharePoint”. 
    • Site Address: Choose your SharePoint Site from the dropdown.
    • Method: Select “Get”
    • Uri: _api/web/lists/getbytitle(“List Name”), other attributes like a top, filter, etc can be added here.

Step 4: Create Item 

Add “Send an HTTP request to SharePoint” action.
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: POST
  • Uri: _api/web/lists/getbytitle(“List Name”)
  • Headers: In the case of a post we need to add a header. In the Headers section, there is a key-value pair combination.
    • content-type :application/json;odata=verbose
    • If-Match :  *
  • Body: JSON body as per business requirements.
     {  
     "__metadata": { "type": "SP.Data.PostDataListItem" },  
     "Title": "New Demo User Post",  
     "Score": 2 ,  
     "TrainingId": 4    
     }  
    
Note: The body part will have a schema of the list item you want to create. Make sure you are including all mandatory columns in the schema. Now, run the flow and check the result.
Success code: 201 means our post method completed successfully. Now we will verify the SharePoint list to check.

Step 5: Update Item

To Update the existing item, we need to use Patch method. Add an Action “Send an HTTP request to SharePoint”.
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: PATCH
  • Uri: _api/web/lists/getbytitle(“List Name”)(ItemID) , id of item which will be updated
  • Headers: In the case of a post we need to add a header. In the Headers section, there is a key-value pair combination.
    • content-type :application/json;odata=verbose
    • If-Match : *
  • Body: JSON Body as per the business requirements.
     {   
     "__metadata": { "type": "SP.Data.PostDataListItem" },   
     "Title": "New Demo",   
     "Score": 2 ,   
     "TrainingId": 4   
     }  
    
Success code: 204 means we have successfully updated the specific list item. Now let’s verify the list item.
We can see that the User Department is updated to HR from IT for Demo User 1.

Step 6: Delete Item

Add an Action “Send an HTTP request to SharePoint” in our existing flow. 
  • Site Address: Choose your SharePoint Site from the dropdown.
  • Method: DELETE
  • Uri: _api/web/lists/getbytitle(“List Name”)(ItemID) , id of item which will be updated
  • Headers: In the case of a post we need to add the header. In the Headers section, there is a key-value pair combination.
    • content-type :application/json;odata=verbose
    • If-Match : *
    • X-Http-Method: DELETE
We are going to target the Item id 4 to delete using the action “Send an HTTP to SharePoint”. Now, run the flow and check the result.

Conclusion:

This is how we can easily implement CRUD operations for SharePoint List item using Power Automate. Isn’t that amazing?
If you have any questions you can reach out our SharePoint Consulting team here.

April 22, 2021

Configure OneDrive Sync Client to sync SharePoint Document Library to Local File System using PowerShell

Introduction:

We implemented an automated Document Library Sync mechanism with OneDrive Sync Client using PowerShell for Construction Engineering Company based out of Washington. Normally, we can sync a SharePoint Document Library with OneDrive Sync Client manually from the user interface very easily. But, here the requirement was to sync Document Library in a dynamic and automated manner with the combination of OneDrive Sync Client & PowerShell.

Scenario:

We were getting a CSV file with URLs of multiple document libraries generated every 24 hours. The requirement was to configure OneDrive Sync Client for URLs of Document Libraries received in the CSV file in an automated manner.  So, we implemented a PowerShell script that will read Document Library URLs from the CSV file and configure OneDrive Sync Client for all the Document Libraries. This PowerShell script then was configured in Windows Task Scheduler for automated execution every 24 hours. Let's see the step-by-step process for this implementation with an example scenario.

Steps & PowerShell Script:

Here, we have taken a CSV file, where we are storing the URLs of the Document Libraries. Please check the below screenshot for the same.
Let’s consider one thing:
  • URL: https://spsite.sharepoint.com/sites/SpaceDemo/A1
    Here - 
  • SpaceDemo = Name of the Site Collection
  • A1 = Document Library Name

To configure the OneDrive Sync Client for a Document Library folder, we need to use the following command in PowerShell.
 odopen://sync/?siteId={” + $siteId + “}&webId={” + $webId + “}&listId={” + $listId + “}&listTitle=” + $listName + “&userEmail=” + $UPN + “&webUrl=” + $siteURL + "&webTitle=" +$webTitle   

Where - 
  • siteId = SharePoint site collection siteId GUID, enclosed in curly brackets. We can get this GUID visiting https://<TenantName>.sharepoint.com/sites/<SiteName>/_api/site/id 
  • webId = SharePoint site webId GUID, enclosed in curly brackets. We can get this GUID visiting https://<TenantName>.sharepoint.com/sites/<SiteName>/_api/web/id 
  • webUrl = SharePoint site URL.      
  • listId =  SharePoint site documents library GUID, enclosed in curly brackets. We can get this GUID visiting the document library in the browser, click in the gear icon and choosing "Library Settings". The URL will show the listId GUID at the end of URL, i.e. https://<tenant>.sharepoint.com/sites/<SiteName>/_layouts/15/listedit.aspx?List=%7Bxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx%7D  (a GUID with escaped curly brackets).
  • userEmail =OneDrive's user email address used to sign in into OneDrive.
  • <webTitle> and <listTitle> are used to compose the name of the local folder where the OneDrive content is synchronized. By default, when we use the "Sync" button when in the browser to synchronize a document library, OneDrive uses the SharePoint site name and the document library name to compose the local folder name, in the form of %userprofile%\<TenantName>\<SiteName> - <DocumentLibraryName>. We can use any other values. If we do not use these parameters, the local folder will be named " - Documents", despite of site and library names.
 
Here, in this sample we will find all above parameters dynamically. Please check the below script for the same.
 Write-Host “Please Enter your UserName” -ForegroundColor Yellow  
 $Username = Read-Host;Write-Host  
 Write-Host “Please Enter your Password” -ForegroundColor Yellow  
 $Password = Read-Host -AsSecureString;Write-Host  
 Import-Csv C:\DOCLIB.csv | ForEach-Object {  
 Write-Host "$($_.DocLibURL)"  
 #Write-Host “Input URL of the SharePoint Site with DOC Library Name and press Enter”  
 $siteURL1 = "$($_.DocLibURL)" #Read-Host;Write-Host  
 $listName = $siteURL1.Substring($siteURL1.LastIndexOf("/")+1)  
 $siteURL = $siteURL1.Substring(0,$siteURL1.LastIndexOf("/"))  
 $webTitle = $siteURL.Substring($siteURL.LastIndexOf("/")+1)  
  #Read-Host;Write-Host  
 $UPN = $Username  
 $creds = (New-Object System.Management.Automation.PSCredential $Username,(ConvertTo-SecureString $Password -AsPlainText -Force))  
 if($siteURL, $libName, $UPN -ne $null)  
 {  
 Connect-PnPOnline -url $siteURL -Credentials $cred  
 #Grabbing Site, Web, and List ID’s  
 $site = Get-PnPSite -Includes Id, URL  
 $siteIDtmp = $site.ID.toString()  
 #Adding some encoding here#  
 $siteID = “%7B” + $siteIDtmp + “%7D”  
 $web = Get-PnPWeb -includes Id, URL  
 $webIDtmp = $web.ID.toString()  
 #Adding some encoding here#  
 $webID = “%7B” + $webIDtmp + “%7D”  
 $list = Get-PnPList -Identity $listName -includes Id  
 $listIDtmp = $list.ID.toString()  
 #Adding some encoding here#  
 $listID = “%7B” + $listIDtmp + “%7D”  
 $resultTMP1 = “odopen://sync/?siteId={” + $siteIDtmp + “}&webId={” + $webIDtmp + “}&listId={” + $listIDtmp + “}&listTitle=” + $listName + “&userEmail=” + $UPN + “&webUrl=” + $siteURL + "&webTitle=" +$webTitle  
 Write-Host $resultTMP1  
 Start $resultTMP1  
 Write-Host "Completed for"+ $siteURL1 -ForegroundColor Green  
 }  
 else  
 {Write-Host “Missing one of the requested values! Please run script again and insert correct values”;return}  
 }   

Test the Script Execution:

First, enter organizational email.

Enter Password and then it will ask for sync. Click on Sync now.

Once the PowerShell script is executed, this will show the following message.

Conclusion:

This is how we can sync SharePoint Document Library with OneDrive. Happy scripting!!

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

January 21, 2021

Implement Search for a Specific Column of Document Library in SharePoint Online

Overview

We at Binary Republik recently implemented the intranet solution for an Engineering & Construction company having headquarters in Boston, Massachusetts, United States. Implementing the tailored search for SharePoint Online - Modern Sites was also the part of requirements. The main purpose of the custom search implementation was to avail the results from a specific Document Library that will target the query on a specific column only.

Example

Let’s consider an example of one of the Document Libraries on our SharePoint site. Let’s say if we have a custom property for our document and when we search the document with that property it should find the document with its value. We want to implement a custom search for a specific document library column. Then how can we implement this?

So, now let’s check the overall procedure.

1.     Create custom properties for the column we wish to configure search.

2.     Go to site setting of the site.

From Site Collection Administration, go to Search Schema. We will be able to see all the manage properties of the site.

URL: https://yourtenant.sharepoint.com/sites/SiteName/_layouts/15/listmanagedproperties.aspx?level=sitecol

3.     To enable column search, we need to create a new custom property.

4.     Select New Managed Property.

5.     Give Name, Description (optional), and Type for the property.

6.    Check the checkbox for Searchable and also for Queryable. This is used the enable the column searches and enable the query for that column.

 7. Check the checkbox for Retrievable for retrieving the column in search call. If we need multiple values from this column, we can check the checkbox "Allow multiple values".


8.  Set the Alias to this property. We can also search based on this alias name instead of the property name.


9. We have to map this managed property with the Crawled Property (the column created in the Document Library should appear in the Crawled Properties). Click on "Add a Mapping".

 

10.  After that search the column name and click on the "Find" button. We are able to see all properties related to the column name, select the appropriate one and click "OK".

11.  Once we add the property, we will be able to see on the below screen.

So, this is how we can configure, managed property for a SharePoint - Document Library column.

Important Notes

·       If we want to implement search on multiple columns, then we need to repeat steps 1 to 11 for each property.

·       After creating custom properties that’s column will be searchable. This will take around 24 hours to crawl this column.

Usability of the Property

E.g.: We need to search "02265" cell phone number. So, we add this number with 'querytext' and we also use 'selectproperties' to select our "Cell Phone". It will search the cell phone number and as result, it will show in cell phone column value.

We can use the following syntax to search in a different manner. We can integrate the same Search API in the SPFx webparts or custom solutions to be implemented.

Conclusion

This is how we can configure the search to target the specific column of SharePoint Document Library!

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

August 12, 2020

Get Attendance Report from Microsoft Teams Meeting

Overview:
In this article, we will learn how we can get an attendance report from Microsoft Teams scheduled call. There are times where we need know number of users who join the call and their duration in a meeting. At that time this concept is very useful to us.

Note: This feature is only available for the Meeting organizers. Attendees will not able to see this option. So, now let’s get started!

Example: Consider the following meeting invite.

Here, Dhruvin is an organizer. Tejal, Shriraj are attendees. To, view the attendance report, Dhruvin (as organizer) needs to click on the “Show Participants” option.

This will open the right pane where Organizer (in this example, Dhruvin) can see an option to download the attendance report. Organizer can download the attendance report before leaving the call.
The report will be downloaded in CSV format and will look as below:
Add caption

Note: If any attendees click on Show Participants, then they will not have an option to download attendance report. See below screen from Attendee's view - Tejal.
Conclusion: This is how we can download the attendance report in MS Teams. Hope this tip helps you.

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

December 30, 2019

How to build a Custom People Picker in Power Apps

In Power Apps - Canvas App, we came across the specific requirement to have a custom people picker where user can search employees by its name and associated email-id should be displayed in the drop-down.

We know, Power Apps doesn’t provide any OOTB people picker without Form control. That’s why we need to build a custom people picker in our App. So, let start creating the custom people picker in Power Apps.


A. Create Custom People Picker:
Please follow the below steps to create our own custom people picker with the suggestion box.

  1. Add Data Source. To add the data source, Go to the View menu and then select Data Sources option.

  2. Click on “Office 365 Users” for adding the Data Source.
                         

  3.  Now, add  List Box” and “Text Input” Control.
    • To add List Box click on “Insert” then on “Controls” -> “ListBox

    • To add Text Box click on “Insert” then in “Text” select “Text Input”.
  4. Select the Textbox control which we have added in Step 3 and configure the following properties.
    • Text Box
      • Default: SelectedUserEMail
      • OnSelect: Set(UsersListBox,true)
    • List Box
      • Items: If(!IsBlank(TextInput2.Text), Office365Users.SearchUser({searchTerm:TextInput2}).Mail)
      • Visible: UsersListBox
      • OnSelect: Set(SelectedUserEmail, ListBox1.SelectedText.Value); Set(UsersListBox,false);Reset(TextInput2)

Now, let’s test our custom people picker!
  • Search for the Employee name in textbox of Custom people picker.
  • It will show the email-id property of that user in the suggestion box. Currently, we have displayed only “Email Property” in the combo box. However, we can show the other Office 365 properties as well.

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

September 12, 2019

Get Members of SharePoint Groups in Excel using Power Query

Challenge:
We have several business units. And in that, for each business unit, we have Approvers, Owners, Members and Viewers. The challenge is to get the members of all business units'  "Approvers" SharePoint group in Excel.

Resolution: 
In the previous blog, we have explained about Power Query in Excel and connecting the SharePoint Lists from SharePoint Online.

Now, using Power Query function we would be getting the list members of SharePoint groups. For this, we would be first creating a function which would get the members of any SharePoint group.

  • For this, we would go to Data > Get Data > From Other Source(s) > From OData Feed. Then, as per the requirement, we need members of the Approvers groups for all business units. So, in this query, we would be fetching the names of the SharePoint groups having "Approvers" in their names and renaming this as "SPGroups".
https://<domain>/_api/web/SiteGroups?$filter=substringof('Approvers',Title)&$select=Title



  • We have the list of SharePoint groups, and now, we would be fetching the members of each SharePoint group, by creating a Power Query function. For this, we would be adding a new blank query and rename it as "GetMemberByGroupName". We know the REST call to get group members is as below:
https://<SiteURL>/_api/web/sitegroups/getbyname('<GroupName>')/users

  • So, we would add a parameter "GrpName" as text, which would make a REST Call for each group, and get all the members. The function (in the Advanced Editor) would be like below:
(GrpName as text) as table =>         
let
    Source= OData.Feed("https://<domain>/_api/web/sitegroups/getbyname('"&Text.From(GrpName)&"')/users?$select=Title")
in
    Source

  • Now, we would go back to SPGroups (1st query) and in the ribbon Add Column > Invoke Custom function. We would select the function and the column name as a parameter and expand the table we get in Custom column.

  • So, here we have the members as per the SharePoint group names.
  • Expand "GetMemberByGroupName" column.
  • So, members for the SharePoint group will be extracted here!

This way, we can have all the members of the selected SharePoint groups in the Excel file using Power Query.

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