0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SharePoint Client Object Model でビューの表示列を変更するコード

Posted at
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','(列内部名)']);
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?