mercredi 21 janvier 2015

Sharepoint COM: Field or property * does not exist after type conversion



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()







0 commentaires:

Enregistrer un commentaire