Showing posts with label Rename Column. Show all posts
Showing posts with label Rename Column. Show all posts

Sunday, January 16, 2022

Power Automate: Useful HTTP Request Actions Part 4

 Hello Friends,

Welcome back with another post on Power Automate. This post is in continuation to one of my earlier post(s) on different ways we can use HTTP request action (Send an HTTP request to SharePoint) in Power Automate to get different kind of information. I will be adding more and more options in this post from time to time. Below is the link of earlier post(s)-

  1. Power Automate: Useful HTTP Request Actions Part 1
  2. Power Automate: Useful HTTP Request Actions Part 2
  3. Power Automate: Useful HTTP Request Actions Part 3
Today, we will learn about below ones-
  1. Create SharePoint List
  2. Create Column(s)
  3. Update Column(s) Display Name
  4. Read Excel And Insert Data
Sometimes, there is a requirement to read an uploaded excel and create List for that in SharePoint and insert items in that list. So, either you need to do this activity manually OR you can use Power Automate to achieve the same. We are discussing Power Automate option here.
  1. Our process will divide into following steps-
    1. Create SharePoint List
    2. Create/Rename Columns In List
    3. Read Excel from Document Library
    4. Add Items from Excel into SharePoint list
Let's start-
  1. Create SharePoint List-
    1. First we will create custom SharePoint list named "SharePointListTemplateIDs" using Power Automate.
    2. Add an action "Send HTTP request to SharePoint".
    3. The Body template used is-
    4. {
      
      	"__metadata":{ "type":"SP.List" },
      	"AllowContentTypes":true,
      	"BaseTemplate":100,
      	"Title":"SharePointListTemplateIDs",
      
      	"Description":"This list contains the IDs of different types of lists/libraries we can create."
      
      }
      
    5. BaseTemplate is the Id that represents to a  List type. 100 is for Custom list. Rest are as below-
    6. This will create list in SharePoint.
  2. Create/Rename Columns In List-
    1. We will create/rename below columns-
      1. Name: (We will not be creating this column. We will use Title Column and will rename it to Name)
      2. TemplateID: (Type: Number; Required: true) 
      3. Description: (Type: Text (Multiline); Required: false)
    2. For this, we will follow below steps-
      1. Rename "Title" to "Name"
      2. Create "TemplateID"
      3. Rename "TemplateID" to "Template ID"
      4. Create "Description"
    3. Inputs are-
      1. Rename "Title" to "Name"
      2. Create "TemplateID"
      3. Rename "TemplateID" to "Template ID"
      4. Create "Description"

  3. Read Excel from Document Library-
    1. Now we will read the Excel file. We had uploaded the file in Documents library. This file contains the Name/TemplateID/Description columns as shown above in the post.
  4. Add Items from Excel into SharePoint List-
  5. That's all. Now save the flow and execute it.
  6. Here's the result-
  7. Please feel free to sent me your queries or any functionality that you want to achieve and currently not able to do so. I would be happy, if would be able to provide it's solution.
  8. Next Post Link-
    1. Coming soon...
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

Saturday, January 15, 2022

Power Automate: Useful HTTP Request Actions Part 3

Hello Friends,

Welcome back with another post on Power Automate. This post is in continuation to one of my earlier post(s) on different ways we can use HTTP request action (Send an HTTP request to SharePoint) in Power Automate to get different kind of information. I will be adding more and more options in this post from time to time. Below is the link of earlier post(s)-

  1. Power Automate: Useful HTTP Request Actions Part 1
  2. Power Automate: Useful HTTP Request Actions Part 2
Today, we will learn about below ones-
  1. Create Column(s)
  2. Update Column(s) Display Name
Sometimes, there is a requirement to create lots of columns in SharePoint list. They may be "Single line of text" or "Number" column. So, either you need to create manually one by one OR you can use Power Automate to achieve the same. We are discussing Power Automate option here.
  1. In order to create columns, first we need an array of columns information
    1. [
      	{
      		"ColumnName":"Column1Text",
      		"ColumnType":"Text",
      		"ColumnTypeKind":2,
      		"Required":"false"
      	},
      	{
      		"ColumnName":"Column2Number",
      		"ColumnType":"Number",
      		"ColumnTypeKind":9,
      		"Required":"false"
      	},
      	{
      		"ColumnName":"Column3Text",
      		"ColumnType":"Text",
      		"ColumnTypeKind":2,
      		"Required":"true"
      	},
      	{
      		"ColumnName":"Column4Number",
      		"ColumnType":"Number",
      		"ColumnTypeKind":9,
      		"Required":"true"
      	},
      	{
      		"ColumnName":"Column 5 With Space",
      		"ColumnType":"Text",
      		"ColumnTypeKind":2,
      		"Required":"false"
      	}
      ]
      
  2. Here, you can see, I have taken a field ColumnDataKind. Basically, it represents the type of column. For more details, you may refer Microsoft docs site-
    1. FieldType enumeration
  3. For Text column it is 2 and for Number column, it is 9.
  4. Now, we need a SharePoint List-
  5. I had created a list named "DynamicColumnsList". It is be default having one column "Title".
  6. Now we are going to create below columns-
    1. Column1Text (Type: Text; Required: false) 
    2. Column2Number (Type: Number; Required: false)
    3. Column3Text (Type: Text; Required: true)
    4. Column4Number (Type: Number; Required: true)
    5. Column 5 With Space (Type: Text; Required: false)
  7. Let's create a flow-
    1. I had initialized a string variable "strColumnsJSONString" and assigned the above mentioned array to this variable.
    2. Now, I am going to parse it. For this, I will use Parse JSON action. I will use same JSON string to create the schema.
    3. Lastly, I will use HTTP Action-
      1. We will use below schema to create columns in Body section and then will assign dynamic values from JSON.
      2. {
        	"__metadata":
        		{
        			"type":"SP.Field"
        		},
        	"FieldTypeKind":,
        	"Title":"",
        	"Required":"",
        	"EnforceUniqueValues":"false",
        	"StaticName":""
        }
      3. Final HTTP action is-
  8. Save it and test it.
  9. As you can see, columns have been created along with the Required (Yes/No) condition. The moment, columns are created, it's Internal Name also get created with same name and gets freezes. In case, if the name has spaces, it replaces with "_x0020_".
  10. Now, if you want to change the Display Name, then you need to repeat the process but this time we will use MERGE.
  11. Below is the JSON used-
    1. [
      	{
      		"ColumnName":"Column1Text",
      		"ColumnType":"Text",
      		"ColumnTypeKind":2,
      		"Required":"false",
      		"DisplayName":"Column 1 Text"
      	},
      	{
      		"ColumnName":"Column2Number",
      		"ColumnType":"Number",
      		"ColumnTypeKind":9,
      		"Required":"false",
      		"DisplayName":"Column 2 Number"
      	},
      	{
      		"ColumnName":"Column3Text",
      		"ColumnType":"Text",
      		"ColumnTypeKind":2,
      		"Required":"true",
      		"DisplayName":"Column 3  Text"
      	},
      	{
      		"ColumnName":"Column4Number",
      		"ColumnType":"Number",
      		"ColumnTypeKind":9,
      		"Required":"true",
      		"DisplayName":"Column 4 Number"
      	},
      	{
      		"ColumnName":"Column 5 With Space",
      		"ColumnType":"Text",
      		"ColumnTypeKind":2,
      		"Required":"false",
      		"DisplayName":"Column 5 With Spaces"
      	}
      ]
      
  12. Same will be used in initializing the string variable as well as in Generate Sample in Parse JSON.
  13. Now the HTTP action will be-
  14. Again Save the flow and test it.
  15. As we can see, the Display Name & the Internal Name are different as we wish to have. This way, we can create and rename the columns in SharePoint list using Power Automate flow.
  16. For adding Choice column (Drop-down menu)-
    1. Input-
    2. Output-
  17. Please feel free to sent me your queries or any functionality that you want to achieve and currently not able to do so. I would be happy, if would be able to provide it's solution.
  18. Next Post Link-
    1. Power Automate: Useful HTTP Request Actions Part 4
With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !

Wednesday, November 17, 2021

PowerApps: Add/Drop/Show/Rename Column

Hello Friends,

Welcome back with some new topics. Today, we will discuss about Column operations in PowerApps. PowerApps provides below options to play on columns-

  1. AddColumns
  2. ShowColumns
  3. DropColumns
  4. RenameColumns

These functions are used to re-shape the collection/table in PowerApps. Apart from that, it also provide functionality to get distinct data using Distinct function.

In this post, we will learn about:

  1. Add/Show/Drop/Rename Column functions
  2. Distinct function
  3. Adding Blank Record (or "Please Select") at Beginning/End of collection (beneficial when binding with Dropdown)
  4. Add ID using Filter function in collection having Distinct data

Let's start one by one. 

  1. First we will create a collection. I had created a collection named "collSampleData". The data is:
  2. ClearCollect(
        collSampleData,
        {
            ID: 1,
            FName: "Sachin",
            LName: "Jain"
        },
        {
            ID: 2,
            FName: "Lokesh",
            LName: "Kumar"
        },
        {
            ID: 3,
            FName: "Rajeev",
            LName: "Khanna"
        },
        {
            ID: 4,
            FName: "Anuj",
            LName: "Sharma"
        },
        {
            ID: 5,
            FName: "Rupesh",
            LName: "Jaiswal"
        },
        {
            ID: 6,
            FName: "Anuj",
            LName: "Sharma"
        },
        {
            ID: 7,
            FName: "Sachin",
            LName: "Jain"
        },
        {
            ID: 8,
            FName: "Sanjiv",
            LName: "Sharma"
        },
        {
            ID: 9,
            FName: "Rajeev",
            LName: "Sharma"
        }
    );  
  3. It will create a collection with 9 records. Here I had added couple of duplicate entries which we will use for Distinct function.
  4. If we check the collection, it has:


  5. Add Column (AddColumns):
    1. AddColumns function is used to add column to the collection/table. You may add a calculated column, add and existing column with different datatype. I am using to add a calculated column by adding FName & LName.
    2. ClearCollect(
          collWithFullName,
          AddColumns(
              collSampleData,
              "FullName",
              FName & " " & LName
          )
      );
      

    3. If we check the collection, it has:

    4. This way, we can add columns to collection.
  6. Show Column (ShowColumns)
    1.  ShowColumns is used to include only those columns in table/collection that needs to be displayed and rest needs to be dropped.
    2. ClearCollect(
          collShowColumnData,
          ShowColumns(
              collWithFullName,
              "ID",
              "FullName"
          )
      );
      
    3. If we check the collection, it has:

    4. Clearly, we can see, only 2 columns are retained and rest are removed. This is useful when we need to show a couple of columns from a large columns list.
  7. Drop Column (DropColumns)
    1.  DropColumns is used to drop the columns from table/collection that needs not to be displayed. It can be say a opposite of ShowColumns.
    2. ClearCollect(
          collWithOnlyFullName,
          DropColumns(
              collWithFullName,
              "ID",
              "FName",
              "LName"
          )
      );
      

    3. If we check the collection, it has:
    4.  

    5. Clearly, we can see, all 3 columns are dropped and rest only 1 column is retained. This is useful when we need to drop couple of columns from a large columns list and rest to be retained.
  8. Distinct (Distinct)
    1. Before moving forward to RenameColumns, we will discuss about Distinct function. After this, you will better understand the RenameColumns function. Distinct function is used to get the distinct values from a table/collection. Distinct works only on single column and return that particular column from the collection.
    2. ClearCollect(
          collDistinctData,
          Distinct(
              collWithOnlyFullName,
              FullName
          )
      );
      


    3. If we check the collection, it has:

  9.  Rename Column (RenameColumns)
    1. RenameColumns is used to rename the name of existing column.
    2. ClearCollect(
          collRenameColumnData,
          RenameColumns(
              collDistinctData,
              "Result",
              "Full Name"
          )
      );
      


    3. If we check the collection, it has:


    4. As we can check the column name has been renamed from "Result" to "Full Name" while the data remains unchanged.
  10. Nested Use Of These Functions
  11. Now, once you are expertise in using functions, you may consolidate all these functions into one. I am using below function in one command to achieve the same functionality-
    1. AddColumns
    2. DropColumns
    3. RenameColumns
    4. Distinct
  12. ClearCollect(
        collConsolidated,
        RenameColumns(
            Distinct(
                DropColumns(
                    AddColumns(
                        collSampleData,
                        "FullName",
                        FName & " " & LName
                    ),
                    "FName",
                    "LName"
                ),
                FullName
            ),
            "Result",
            "Full Name"
        )
    );
    


  13. If we check the collection, it has:


  14. Add Blank Record At Beginning/End of Collection
  15. We have consolidated data collection. We will add a blank record at the end of collection.
  16. ClearCollect(
        collBlankAtEnd,
        collConsolidated,
        {'Full Name': Blank()}
    );
    

  17. For the purpose to display blank record, I had set border of labels used.
  18. Now, we will add a blank record at the beginning of collection.
  19. ClearCollect(
        collBlankAtBegin,
        {'Full Name': Blank()},
        collConsolidated
    );  

  20. Add ID using Filter function in collection having Distinct data
  21. Now suppose a scenario, where you have a collection which is having multiple duplicate records. Your objective is to have Distinct records having ID and Name. The problem is that Distinct function returns only single column, so what the approach is?
    1. We will create a collection.
    2. Apply Distinct (to get distinct records) >> AddColumns (add ItemID column with default value as 0) >> RenameColumns (rename the column "Result" created as as result of Distinct function to ItemName).
    3. Create a replica of this distinct collection to apply ForAll loop.
    4. Apply ForAll loop. In this loop apply Patch. In Patch, use Filter with First function to get the desired ItemID of each item.
  22. Sequentially code is as below-
    1. ClearCollect(
          collStationeryData,
          {
              ID: 1,
              ItemName: "Pencil"
          },
          {
              ID: 2,
              ItemName: "Pen"
          },
          {
              ID: 3,
              ItemName: "Eraser"
          },
          {
              ID: 2,
              ItemName: "Pen"
          },
          {
              ID: 4,
              ItemName: "Sharpner"
          },
          {
              ID: 5,
              ItemName: "Paper A4"
          },
          {
              ID: 1,
              ItemName: "Pencil"
          },
          {
              ID: 3,
              ItemName: "Eraser"
          },
          {
              ID: 6,
              ItemName: "Stapler"
          }
      );
      
    2. ClearCollect(
          collDistinctStationeryData,
          RenameColumns(
              AddColumns(
                  Distinct(
                      collStationeryData,
                      ItemName
                  ),
                  "ItemID",
                  0
              ),
              "Result",
              "ItemName"
          )
      );
      
    3. ClearCollect(
          collDistinctStationeryDataTemp,
          collDistinctStationeryData
      );
      
    4. ForAll(
          collDistinctStationeryDataTemp,
          Patch(
              collDistinctStationeryData,
              LookUp(
                  collDistinctStationeryData,
                  ItemName = collDistinctStationeryDataTemp[@ItemName]
              ),
              {
                  ItemID: First(
                      Filter(
                          collStationeryData,
                          ItemName = collDistinctStationeryDataTemp[@ItemName]
                      )
                  ).ID
              }
          )
      );  

  23. If we check the collection, it has:
    1. collStationeryData

    2. collDistinctStationeryData (initial stage before Patch) / collDistinctStationeryDataTemp

    3. collDistinctStationeryData (After Patch)

  24. This way, you can utilize these power packed functions as per the required. Even you may nest these functions to avoid multiple steps.

With this, I am concluding this post.
Happy Coding !!!
Will see you again with some new topics.

Stay Safe !
Stay Healthy !