Quantcast
Channel: Microsoft Online: SharePoint Online forum
Viewing all articles
Browse latest Browse all 10096

How to delete a lookup field (FieldLookup) in a list using csom

$
0
0

Hi there,

I'm trying to delete a lookup field in a list using CSOM but it appears not to be possible.

Tryed the following combinations:

FieldLookup columnToDeleteLU = (FieldLookup)columnToDelete;
columnToDeleteLU.DeleteObject();
list.Update();
ctx.ExecuteQueryandRetry();

OR

Field columnToDeleteLU = list.Fields.FirstOrDefault(x => x.Id == columnDelete)
columnToDelete.DeleteObject();
list.Update();
ctx.ExecuteQueryandRetry();

And I always get the error:

The primary lookup field cannot be deleted. There are dependent lookups created on this primary lookup field that should be deleted first."


I tried to use the

 var primaryFieldID = columnToDeleteLU.PrimaryFieldId;
list.Fields.FirstOrDefault(x => x.Id == columnDelete).DeleteObject();
list.Update();
ctx.ExecuteQueryandRetry();

Also with no success. I'm a little stuck here. Any ideas?



Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>