1

I am getting this error while updating discussion item's any property on SharePoint online. Error doesn't occur in case of document library and custom lists. Error Code is -2147024809 my code goes like this

 public bool propudate(string siteCollectionUrl,string webUrl ,SBUpdatePropsRequest updateRequest)
    {
        var updateResponse = new SBUpdatePropsResponse();
        var clientContext = Admin.GetAuthenticatedClientContext(webUrl);
        var web = clientContext.Web;
        var oList = clientContext.Web.Lists.GetById(updateRequest.ListID);

        var itemProps = updateRequest.ItemProperties;
        var itemUserProps = updateRequest.UserTypeProperties;
        var itemDateTimeProps = updateRequest.DateTimeItemProperties;

        ListItem listItem = oList.GetItemById(updateRequest.DocID);
        clientContext.Load(web);
        clientContext.Load(listItem);
        clientContext.ExecuteQuery();                   
        try
        {
            //Need to create a extra dictionary to save server time against property                
            var itemDateTimePropsLocal = new Dictionary<string, string>();
            foreach (var prop in itemDateTimeProps)
            {
                var dateTimeLocal = new DateTime(prop.Value, DateTimeKind.Utc);
                var temp = web.RegionalSettings.TimeZone.UTCToLocalTime(dateTimeLocal);
                clientContext.ExecuteQuery();
                itemDateTimePropsLocal.Add(prop.Key, temp.Value.ToString());
            }

            foreach (var userProp in itemUserProps)
            {
                if (userProp.Value != null && !string.IsNullOrEmpty(userProp.Value.ToString()))
                {
                    var uservalues = userProp.Value as int[];
                    //Handle for multi user property
                    if (uservalues.Length > 1)
                    {
                        var propValues = new List<FieldUserValue>();
                        foreach (var values in uservalues)
                        {
                            if (values > 0)
                                propValues.Add(new FieldUserValue { LookupId = values });
                        }
                        listItem[userProp.Key] = propValues.ToArray();
                    }
                    else
                        listItem[userProp.Key] = (new FieldUserValue { LookupId = uservalues[0] });
                }
            }             

            foreach (var prop in itemProps)
            {
                if (prop.Key.Equals("ContentType"))
                    continue;
                if (prop.Value != null && !string.IsNullOrEmpty(prop.Value.ToString()) && prop.Value.GetType() != typeof(FieldUrlValue))
                    listItem.ParseAndSetFieldValue(prop.Key, prop.Value.ToString());
            }

            foreach (var prop in itemDateTimePropsLocal)
            {
                listItem[prop.Key] = prop.Value;
            }
            listItem.Update();
            clientContext.ExecuteQuery();
            updateResponse.IsSuccess = true;
        }
        catch(Exception ex)
        {
            Logging.LogWriteLine("Failed to update list item properties", ex);
            updateResponse.IsSuccess = false;
        }

}

  • what is the error message? – Atish Dipongkor - MVP Sep 22 '16 at 8:58
  • Error message is in the title. – eeshwr Sep 22 '16 at 8:58
  • Would really help if you could provide a more complete code sample. Also a complete error message always helps rather than just saying "Error is in the title" which answers where the error is not what the error. – Tanmay Sep 22 '16 at 10:54
  • ServerException: Invalid data has been used to update the list item. The field you are trying to update may be read only. at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream) at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse() at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb) at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery() at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery() at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery() at – eeshwr Sep 22 '16 at 11:13
  • This error occurs only if I try to update the discussion properties. – eeshwr Sep 22 '16 at 11:13

Your Answer

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

Browse other questions tagged or ask your own question.