How to update multiple-choice field in sharepoint with WCF / Rest web services?

I searched this on the Internet for 4 days and I still don't know why my code is not working ...

I am using an ASP.NET MVC 4 application with a link to a sharepoint listData link for CRUD data.

This is how I retrieve my DataContext:

var datacontext = new CogniTICDataContext(new Uri("http://my.service.url/_vti_bin/listdata.svc")); datacontext.IgnoreResourceNotFoundException = true; datacontext.Credentials = new NetworkCredential("user", "pass", "Domain"); datacontext.MergeOption = MergeOption.OverwriteChanges; return datacontext; 

It works great with one and several search fields. But with multiple selection fields nothing works.

Here is what I am trying:

  foreach (string domComp in jsonDomComp.Split(';')) { PrestatairesFormationsDomaineDeCompétencesValue domaineDeCompetence = PrestatairesFormationsDomaineDeCompétencesValue .CreatePrestatairesFormationsDomaineDeCompétencesValue(domComp); prestataire.DomaineDeCompétences.Add(domaineDeCompetence); //dc.AttachTo("DomainesDeCompétence", domaineDeCompetence); //dc.AddLink(prestataire, "DomComp", domaineDeCompetence); } //SaveChanges in batch mode dc.UpdateObject(prestataire); dc.SaveChanges(System.Data.Services.Client.SaveChangesOptions.Batch); 

I commented on AttachTo and AddLink because my "DomaineDeCompétences" are not entities! This is not a search field much, and I can not change it. Although, if I try to add these two lines, I have a ResourceNotFoundException because the object does not have an identifier, and this is because it is not an entity! (I already tried: dc.IgnoreResourceNotFoundException = true;)

I have no errors, it just doesn't work ... Can someone help me?

Regards, Flavio

+4
source share
2 answers

instead

 prestataire.DomaineDeCompétences = ... 

just use

 prestataire.DomaineDeCompétencesValue = domComp 

there you can directly assign a string.

0
source

Please look at a similar question on SO

SP 2013 - Updating a multi-valued search field using the REST API

and

Updating search values ​​using the REST API

It is also possible:

 MyListService.Credentials = CredentialCache.DefaultCredentials; MyListService.Url = "http://yourserver/_vti_bin/lists.asmx&quot;; XmlDocument updateRequest = new XmlDocument(); String updateBatch = "<Batch OnError='Continue'>" + "<Method ID='1' Cmd='Update'>" + "<Field Name='ID'>2</Field>" + "<Field Name='Location'>1;#;#2</Field>" + "<Field Name='Owners'>1;#;#7</Field>" + "<Field Name='Choices'>Value1;#Value2</Field>" + "</Method>" + "</Batch>"; updateRequest.LoadXml(updateBatch); XmlNode deleteResult = MyListService.UpdateListItems("Tasks", updateRequest.DocumentElement); 
-1
source

Source: https://habr.com/ru/post/1482562/


All Articles