How to Update DataTable to SharePoint List?

Hi Team,
I have a datatable and Sharepoint list with the same headers (Same number of rows and column)
Now I want to update the datatable to the SharePoint list
Can Anyone help?

@Palaniyappan @Yoichi Can you guide me?

@u322805
Can you try these steps:

  1. Use the “Read Range” activity to read the SharePoint list into a DataTable. This will allow you to retrieve the existing data from the SharePoint list.
  2. Manipulate the DataTable as needed. You can perform any necessary transformations or updates to the DataTable, such as adding, modifying, or deleting rows.
  3. Once you have the updated DataTable, use the “Clear List” activity to clear the existing data from the SharePoint list. This step is optional and depends on your requirements. If you want to completely replace the existing data with the updated DataTable, you can clear the list before adding the updated data.
  4. Loop through the rows of the DataTable using a “For Each Row” activity.
  5. Inside the loop, use the “Add Item” or “Update Item” activity to add or update each row of data in the SharePoint list. Map the columns of the SharePoint list to the corresponding columns in the DataTable using the appropriate field mappings.
  6. Configure the necessary authentication and connection settings for the SharePoint activities. You can use the SharePoint Application Scope activity to specify the SharePoint site URL and provide the required credentials or authentication method.
  7. Test and execute your workflow to update the SharePoint list with the updated DataTable.

@u322805

Use add list items activity and pass the datatable as input

And the first row in datatable should be the column names in sharepoint you want to add to…and from second row you can have data

Cheers

@Anil_G Thanks for your reply
Am getting the add list item like this
image

No field to pass datatable

@u322805

Can you please confirm if you are using office 365 activities or sharepoint activities

Cheers

@Anil_G am using SharePoint Activities

image

@u322805

You want to update or add?

If add then need to use in a loop as we have option to add only 1 item once

If upfate…then g
First do get items…then in loop update the values and then use update items

Cheers

@Anil_G Thank you

I want to add, may I know what is the input that should be given to the Prop Dictionary Field?
I have my data in a data table, or should I install any packages to get activities in which datatable can be given as input?

@u322805

Add items takes a dictioanry type variable in which key is the field name and value is the corresponding value for that column/field

Create dictionary of dictionary(string,string) and initialize it with dictionary(of string,string)
You can create usingn assign dict("columnname") = "value"

Then the dictionary can be given as input to add items

You can as well download official UiPath office 365 activities but it needs a different authentication not sure if you have that setup

https://docs.uipath.com/activities/docs/office365-setup

Cheers

Hi @raja.arslankhan Thank you for your reply

How to I give the datatable input to the Prop Dictionary field or should I install

Hi @Anil_G thanks again
I have tried as you have instructed
Below is the data table
image

This is the UiPath Workflow I did

The output I received is
image

Now am getting the first column value as “Key” and the second column value as “Dictionary Value”
But I want the Key as Header and the Value is first row value
Can you guide me on this, thanks

@u322805

Update field would be the column name directly or use dt.Columns(0).ColumnName

And update value would be currentrow(0).ToString

And if you keep add inside loop it would add item for every iteration

Ideally for evry row you have to use another for loop for all column inside so that dictionary will be hving all columns values

In the first loop use this is to initialize dictionary dict = New Dictionary(Of string,Object)

Basically inside the for loop use another for each with dt.Columns and use type argument as columns

And use assign inside it and give

dict(currentitem.ColumnName)=currentrow(currentitem.columnname).ToString

Cheers

Hi @Anil_G Thank you for the tips
I did as you instructed but columnname is taken as the value and not header
image
image
The header should be Job_Name and not DAP_UIP00009-01

Workflow Used:

@u322805

This si what you have to use…you assigned both as values

Cheers

Keeping : in between wont create a dictionary

Datatable for loop is to be present outside and column loop should be inside

Cheers

Hi @Anil_G I tried
Below is the workflow and output


image

Issue: Not Updating in the same row and not iterating through next column values column headers are ok though

@u322805

This is how it should look

Please correct

cheers

1 Like

Hi @Anil_G ,
Thank you for this

Used this any idea why the Sharepoint list is updating values in the new row each time instead of updating in the same row

And How to assign the value (in the dictionary) to add to Sharepoint List

@u322805

Can you please show a full screenshot of a your workflow…

Looks like what you did is to use for loop on column and then used currentrow(0).ToString as value…

So the same value is added to dictionary but with different column names as you are looping on column and for each column a new item is added as add item is present inside the loop

What I showed in screenshot is different and what you used is different…currentrow(0) will always take the first column value only

Cheers

1 Like

Hi @Anil_G ,
Attaching the XAML file below with this workflow am able to get the details as expected except that list is being added in new rows each time,
I believe Sharepoint sequence should be outside of For each Column loop, so I
tried adding Key and Value to Dictionary inside this loop using “Add to Dictionary” activity and then pass this dictionary variable in Add Item to Sharepoint activity
But the dictionary type is different
Dictionary I initialized is of type Dictionary(of String, Object) but add to Dictionary is expecting Dictonary (of String, String),
how do we deal this

TestingAddListdata.xaml (16.0 KB)

Output Image

image

@u322805

This is how it should be …corrected the details

TestingAddListdata (1).xaml (13.5 KB)

cheers