0

I have a Sharepoint 2013 O365 App that is Autohosted. It is doing a simple list item creation on a remote sharepoint list in the site that owns the app. I have added app permissions of all kinds to test this but currently its set for Site Collection Write, Web Write, and List Write. What happens is an item gets created but has nothing in it. No title, no other meta data. It does get set on the CSOM object, but when it comes back from the server the fields are null again. When I look at the list, it shows the same... empty list items. So they get created... but with no data.

        using (var clientContext = TokenHelper.GetClientContextWithContextToken(SPHostUrl, contextToken, Request.Url.Authority))
        {
            var web = clientContext.Web;
            var reports = web.Lists.GetByTitle("SomeList");
            clientContext.Load(reports);

            clientContext.ExecuteQuery();
            Response.Write("Total Something: " + reports.ItemCount.ToString());


            clientContext.Load(reports);

            clientContext.ExecuteQuery();

            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            var newReport = reports.AddItem(itemCreateInfo);

            newReport.Update();
            clientContext.Load(newReport);
            clientContext.ExecuteQuery();

            newReport.FieldValues["Title"] = "aaaaa";

            newReport.FieldValues["SomeOtherTitle"] = "aaaaaaa";
            newReport.FieldValues["Location"] = "NO LOC";


            newReport.FieldValues["SomeType"] = "bbbbb";

            newReport.Update();
            clientContext.ExecuteQuery();
        }
1

You should use newReport.set_item('Title', 'aaa'); to update a field value I think.

Check out this great intro from MSDN on how to perform CRUD with Client object model, yes it is for 2010, but the methods are the same for 2013.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.