function changeViewFields(ListName, ViewName, Fields){
// コンテキストオブジェクト取得
var custCtx = SP.ClientContext.get_current();
// サイトオブジェクト取得指示
var custWeb = custCtx.get_web();
// リスト(ライブラリ) オブジェクトの取得指示
var custList = custCtx.get_web().get_lists().getByTitle(ListName);
// ビューオブジェクトの取得指示
var custView = custList.get_views().getByTitle(ViewName);
custCtx.load(custView);
// ビュー表示列オブジェクトの取得指示
var custViewFields = custView.get_viewFields();
custCtx.load(custViewFields);
// 取得実行
custCtx.executeQueryAsync(
// 成功時ハンドラ
function () {
custViewFields.removeAll();
for(i = 0; i < Fields.length; i++) {
custViewFields.add(Fields[i]);
}
custView.update();
custCtx.executeQueryAsync(
// 成功時ハンドラ
function () {
alert('Change view [ ' + ListName + ' - ' + ViewName + ' ] fields complete.');
}, function (sender, args) {
alert('Change view [ ' + ListName + ' - ' + ViewName + ' ] fields failed. ' + args.get_message() + '\n' + args.get_stackTrace());
} // 失敗時ハンドラ
);
}, function (sender, args) {
alert('Get view [ ' + ListName + ' - ' + ViewName + ' ] fields failed. ' + args.get_message() + '\n' + args.get_stackTrace());
} // 失敗時ハンドラ
);
}
changeViewFields("(リスト表示名)", "(ビュー表示名)", ['ID','Title','(列内部名)']);
More than 5 years have passed since last update.
SharePoint Client Object Model でビューの表示列を変更するコード
Posted at
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme