SharePoint Update List Items

Hi all,

Currently have a process which reads all list items from a SharePoint list and this has been working fine for years using the activities on Marketplace which UiPath staff developed. We’ve had a Change Request to add some code to update any list items which get processed as a result of this job running, updating a new field called “Processed” and changing it from No to Yes. Even using the same SharePoint scope and testing by using the Get List Items activity we are struggling to update anything.

When we have it as below (with “Read, Write” selected in the properties of the SharePoint Scope) Get List Items works, and the first Update List Items doesn’t throw any errors, but the one in the For Each complains of “Update list items: Access denied. You do not have permission to perform this action or access this resource.”

However, although the first one doesn’t throw errors it doesn’t seem to work. All items show as having been updated by the VM this test process ran on within their version history, no change actually gets made.

Update List Item properties:
Prop Dictionary: New Dictionary(Of String, Object) From {{ “Processed”, “Yes”}}
CAMLQuery: “” - to hopefully just get all items

Has anyone successfully used this activity to update list items in SharePoint? We need to use these activities due to the version of SP being used, the more modern O365 activities don’t work.

Thanks

@Alex_Cross

Inside loop it might be throwing error in same scope because the queries are executed at once in this activity…so as the previous update might be conflicting

can you try to use the loop with scope inside it

Also why you want to update all items in loop?

cheers

Apologies, looks like I screenshotted and shared info for the incorrect test file!

The error is: “Update list items: This field cannot be updated.”
CAML:
"<Query><OrderBy><FieldRef Name='ID' Ascending='True'></FieldRef></OrderBy><Where><Eq><FieldRef Name='ID'></FieldRef><Value Type='Number'>"+ID+"</Value></Eq> </Where></Query>"

image

When we manually open SP we are able to Edit this field.

Updated item in prop dict to be our code from above (rather than using the variable) and it processed, however similar to before, although it shows as having worked, nothing in SharePoint actually updates to show Yes in that column?

image

@Alex_Cross

  1. Your item variable is having ID as well…and I dont think ID can be updated
  2. Can you try giving only that value you want to update in the dictionary instead of all the columns…

The value shpuld be given as number…is it given as number or string?

Cheers

Please ignore item variable, I updated that to be New Dictionary(Of String, Object) From {{ “Processed”, “Yes”}} instead as you can see in the latest screenshot, so it should only update the Processed field to Yes? As far as I know the CAMLQuery under Prop Dictionary defines which items are accessed, so to define that you need the ID in it?

The value is string, we’re updating it to “Yes”, if that’s what you mean?

The item variable is from the for each loop, so it’s actually the dictionary item for each ID line

@Alex_Cross

Did you try the caml query exactly in get list items ?

Is it giving the value?

Cheers

I’m using "<Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query>" in Get List and it grabs all items.

In Update all - "<Query><OrderBy><FieldRef Name='ID' Ascending='True'></FieldRef></OrderBy><Where><Eq><FieldRef Name='ID'></FieldRef><Value Type='Number'>"+ID+"</Value></Eq> </Where></Query>"

All the items in SharePoint show as the bot having updated them as this ran, but the Processed column still shows No.

@Alex_Cross

Can you try the update all query in your get list items and check if it is returning anything…may be usinng is it is not getting filtered properly

As ideally you are not having any error pop up as well

Cheers

When running it we got the output showing each ID was being updated and they tracked perfectly with the number of records we have in SP:
image

And as I said, in SharePoint, each item has “Last updated by bot at hh:mm:ss” every time we run it, so it is getting through to each item, just not actually updating them?

@Alex_Cross

Can you try using the same query that you are using in update with an id value in it

in get list items use the same query…

May be caml query is filtering all items completely…

and is the name of Processed field correct?it is the backend name that you need to give…is it having two columns with same name?

cheers

I tried updating the CAML in Update to just be 6 for the ID, which is the first line’s ID, that “worked” but didn’t update it.

The field is called Processed, I even copy and pasted to make sure there weren’t hidden spaces etc. Only one field of that name as well.

I’ll try and use the same CAML we are using in Update in Get as well, see if it helps.

Thanks!

@Alex_Cross

Please try with get that confirms if a item is being retrieved or not with the caml query

Apart from that can you get the list items and check if youa re getting No or 0 as the value…is the field type text or something else?

cheers

Used item(“Processed”).tostring and saw it was in fact Boolean, so even though it showed Yes/No, it was looking for True/False.

Successfully now updated fields, thanks so much for your help!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.