如何使用 JSOM 更改 SharePoint 在线列表的列类型?

事情阿里

我想使用 JSOM 更改列表的列类型。“可计费”列的类型是布尔值,我需要将列类型更改为“单行文本”。

有什么方法可以改变列的类型吗?

这是代码:

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());
}
Michael Han_MSFT

您需要使用 SP.Field.set_typeAsString() 方法来更改列类型,以下是我的示例:

var list = web.get_lists().getByTitle("Mylist");
field = list.get_fields().getByInternalNameOrTitle("Billable");   
field.set_typeAsString("Text");
field.update();

参考:https : //docs.microsoft.com/en-us/previous-versions/office/sharepoint-visio/jj245910(v=office.15)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用 JSOM 在 SharePoint 列表中插入 5000 多个项目?

如何使用 JSOM 获取 SharePoint 站点中存在的所有文档库的列表?

使用JSOM获取SharePoint网站中的所有列表和列表项

使用jsom在Sharepoint中获取术语及其子术语

成功调用 JSOM update() 后,SharePoint 列不更新

尝试使用 JSOM CDL 从提供商托管的加载项部分访问 Sharepoint Online 主机 Web 列表数据时出错

JSOM API发生未知错误-Sharepoint 2013(向多个唯一的内容类型添加多个唯一的网站列)

.NET Graph SDK更新SharePoint在线列表项值

使用 C# 在线列出 Sharepoint 上文件夹中的所有文件

Sharepoint在线列格式-以文本显示值

如何使用 Rest 在 SharePoint 中获取多个模板类型列表

Sharepoint-如何删除未使用的列

如何使用MsGraph获取SharePoint超链接列类型

如何使用SharePoint Plus API在SharePoint Designer 2013中获取SharePoint“审批状态”列数据

如何更改列表的类型?

使用 pnp PowerShell 更新 SharePoint 在线文档库列属性

如何从Sharepoint解析文件列表

如何在sharepoint中将undefined的值更改为空白

添加链接 Sharepoint 2013 时如何更改默认值

使用 C# 更改文件的 Microsoft Sharepoint 字段值?

从SharePoint在线使用Secure Azure API

使用C#从SharePoint Online外部获取SharePoint列表数据

SharePoint 2013 CSOM 上传文档和更改列值

如何在使用 Powershell 的前提下更改 Sharepoint 2019 中多个视图的样式

使用 api Sharepoint 和 Postman 更新 Sharepoint 元数据列

SharePoint:如何按内容类型ID获取列表项?

如何使用 spfx 检索 SharePoint 列表项附件?

如何使用图谱API获取SharePoint Online列表项附件?

如何使用javascript从Sharepoint列表中获取值