0

I am working on a visual web part of SP 2013 Server that allow user to change the list column properties. Everything goes fine. The error is: when I change the column type, it was successfully updated, but, when I load it a again, the error occurs. Then if I refresh the page, it's gone.

This is the code for the update:

function UpdateField(FID) {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle("My list");
    var field = list.get_fields().getById(FID);

    field.set_typeAsString(type); // type can be: Text, Note, Number,...

    field.update();
    context.load(field);
    context.executeQueryAsync(function () {
       alert("Successfully updated!")
    },
    function (sender, args) {
        alert(args.get_message());
    });
}

The code for the reload:

function LoadField(FID) {
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var list = web.get_lists().getByTitle("My list");
    var field = list.get_fields().getById(FID);

    context.load(field); // The error occurs right here, but if the page is refreshed, the error is no more
    context.executeQueryAsync(function () {
        alert("Successfully reloaded!");
    }, function (sender, args) {
        alert(args.get_message()+": "+args.get_stackTrace());
    });
}

And here is the error log when I change a field type from Single Line Text to Multiple Lines Text:

Field or property "MaxLength" does not exist.: at Microsoft.SharePoint.Client.ServerStub.WriteAsJson(JsonWriter writer, Object obj, ClientObjectQuery objectQuery, ProxyContext proxyContext) at Microsoft.SharePoint.Client.ServerStub.WriteAsJsonWithMonitoredScope(JsonWriter writer, Object value, ClientObjectQuery objectQuery, ProxyContext proxyContext) at Microsoft.SharePoint.Client.ClientMethodsProcessor.WriteQueryResults(Object obj, ClientObjectQuery objQuery) at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessQuery(XmlElement xe) at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessOne(XmlElement xe) at Microsoft.SharePoint.Client.ClientMethodsProcessor.ProcessStatements(XmlNode xe) at Microsoft.SharePoint.Client.ClientMethodsProcessor.Process()
  • How are you calling UpdateField() and LoadField()? – Vivek Athalye Jan 22 '15 at 5:02
  • Did you get the answer ? I'm also facing the same issue. – Manu Singh Oct 8 '15 at 7:30
  • Yes, what I did was trying to reload the context, not the current. You may try to replace this var context = new SP.ClientContext.get_current(); with this: var url = new SP.ClientContext.get_current().get_url(); var context = new SP.ClientContext(url); – Caleb Mar 3 '16 at 6:12

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.