Javascript 如何使用JSOM更改SharePoint online列表的列类型?
我想使用JSOM更改列表的列类型。列“Billable”的类型是布尔型的,我需要将列的类型更改为“单行文本” 是否有任何方法可以更改列的类型 以下是代码:Javascript 如何使用JSOM更改SharePoint online列表的列类型?,javascript,sharepoint-online,sharepoint-list,sharepoint-jsom,Javascript,Sharepoint Online,Sharepoint List,Sharepoint Jsom,我想使用JSOM更改列表的列类型。列“Billable”的类型是布尔型的,我需要将列的类型更改为“单行文本” 是否有任何方法可以更改列的类型 以下是代码: var oFields, clientContext; function UpdateListField() { // You can optionally specify the Site URL here to get the context // If you don't specify the URL, the met
var oFields, clientContext;
function UpdateListField() {
// You can optionally specify the Site URL here to get the context
// If you don't specify the URL, the method will get the context of the current site
// var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");
clientContext = new SP.ClientContext(appUrl);
var web = LawApp.Repositories.getWeb(clientContext, hostUrl);
var olistCollection = web.get_lists();
var oList = olistCollection.getByTitle("ODMatter");
oFields = oList.get_fields();
clientContext.load(oFields);
// Execute the query to the server.
clientContext.executeQueryAsync(onsuccess, onfailed);
}
function onsuccess() {
// Iterate through Enumerator
var oEnumerator = oFields.getEnumerator();
while (oEnumerator.moveNext()) {
var oField = oEnumerator.get_current();
// Enter the field name here
if (oField.get_title() == "Billable") {
oField.FieldType("text");
oField.update();
break;
}
}
// Execute the query to the server.
clientContext.executeQueryAsync(FinalQuerySuccess, FinalQueryFailure);
}
function onfailed(sender, args) {
console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
}
function FinalQuerySuccess(sender, args) {
updateCurrentVersion();
console.log('Success');
}
function FinalQueryFailure(sender, args) {
console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
}
您需要使用SP.Field.set_typeAsString()方法来更改列类型,下面是我的示例:
var list = web.get_lists().getByTitle("Mylist");
field = list.get_fields().getByInternalNameOrTitle("Billable");
field.set_typeAsString("Text");
field.update();
参考资料:非常感谢你的帮助,因为它现在正在工作。你能告诉我“多行文本”的这种方法应该传递什么吗。您在方法中传递的“Text”正在将列类型更改为单行文本。字段。设置类型字符串(“文本”);我还需要将另一列的类型从“单行文本”更改为“多行文本”。若要更改为“多行文本”,请使用field.set_typeAsString(“Note”)。如果我的答案对你有帮助,请接受它作为答案并向上投票:)你好,Michael Han_MSFT,你能帮我回答这个问题吗?