4

I've been looking for this on the web for 4 days, and i still have no clue why my code isn't working...

I'm using an ASP.NET MVC 4 application with a service reference to a sharepoint listData in order to CRUD datas.

Here 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's perfectly working with single and multi lookup fields. But with multi choice fields, nothing is working.

Here is what i'm 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 the AttachTo and AddLink because my "DomaineDeCompétences" are not entities ! It's not a multi lookup field and i have no power to change that. Though, if I try to add those two lines, I have a ResourceNotFoundException because the entity has no id, and that's because it's not an entity ! (I already tried : dc.IgnoreResourceNotFoundException = true;)

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

Best regards, Flavio

user1800356
  • 295
  • 4
  • 13

2 Answers2

1

instead of using

prestataire.DomaineDeCompétences = ...

just use

prestataire.DomaineDeCompétencesValue = domComp 

there you can assign the string directly.

SolarX
  • 1,873
  • 2
  • 18
  • 26
-2

Please have a look a similar question on SO

SP 2013 - Updating a multi-value lookup field via the REST API

and

Updating Lookup Values with the REST API

Also possible:

MyListService.Credentials = CredentialCache.DefaultCredentials;
MyListService.Url = "http://yourserver/_vti_bin/lists.asmx";

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);
Community
  • 1
  • 1
STORM
  • 4,005
  • 11
  • 49
  • 98