Flow Exchange

Please login or click SIGN UP FOR FREE to create your FlowUG account to join this user group.

Create a SharePoint List from another list

By Rasika Chaudhary posted Oct 29, 2018 02:43 PM

  
I have been working on Microsoft Flows Customer support team for quite some time now and one very common ask from customers is : How to create a SharePoint list from another list. 
So far flow actions for SharePoint allows users to create, copy or delete items from one list to other. However, we don't have actions, which will create the List itself. With Send HTTP request to SharePoint action in flows, its now very easy to leverage rest api calls to perform a lot of custom actions. 

In my flow, I am calling Sharepoint Rest API to list all the fields in Source List A. The following rest api call is used to list all the Fields in Source List A:
_api/web/lists/GetByTitle('ListA')/Fields?$filter=Hidden eq false and ReadOnlyField eq false"}]}

You can further filter this call to return only 2 attributes:
  • Title (Returns name of the column)
  • FieldType (Returns column type)
I have noticed that the above call returns 3 columns which are already present by default when a new list is created. I am using filter function to remove already available columns by using following filter: 
@and(not(equals(item()['Title'], 'Title')),not(equals(item()['Title'], 'Attachments')),not(equals(item()['Title'], 'Content Type')))

ListFieldsFromSource
After this action, I get an array of Field Names and Field Types that are custom created in List A and now my next task is to create List B and then add these columns in List B. The following Rest API call will create the New List.
Note that I am using Send HTTP request to Sharepoint action for all these calls.
CreateListB
Once this is done, my next task is to browse through the array of fields and add these fields to the newly created List B. I am setting a variable to browse through the array elements. Compose call returns the output from create List, which gives us the List B path.
GetLinkofNewListB
InitializeCounter
Following do-until call browse through the array of fields and add it to new List B. Formula used to navigate each array element: 
body('Select')[variables('i')]?['Title']
body('Select')[variables('i')]?['FieldType']

Do-untilLoop
This will create a exact copy of list A as List B. 

There might be more solutions out there. But until you find those, hope this article gives you a head start.
Happy Automating.. !!!

Attaching link to download this flow:  Download Flow
0 comments
21 views

Permalink