1
1

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 3 years have passed since last update.

ServiceNow - テーブル列のラベル一覧又は名前一覧を表示するスクリプト

Last updated at Posted at 2020-10-27

概要

仕様書を作成する場合にテーブル列一覧をExcelに記述する場合がある。アプリケーションナビゲータの「Tables」から列一覧を表示することはできるが、仕様書にコピーペするのが面倒。
その場合のために作成したスクリプトです。

実装

バックグラウンドスクリプトから次を実行する。

var tableName = 'cmdb_ci_ip_switch';

//var col = 'label';  // 'label', 'name', 'type'
var col = 'name';
//var col = 'type';

var values = [];


var fields = new GlideRecord('sys_dictionary');
fields.addQuery('name', tableName);
fields.addEncodedQuery('internal_type!=collection^ORinternal_type=NULL');
fields.query();
while(fields.next()) {
  //gs.info(fields.column_label.toString()+ ',' + fields.element.toString());
  switch(col) {
    case 'name':
      values.push(fields.element.toString());
      break;
    case 'type':
      values.push(fields.internal_type.toString());
      break;
    default:
      values.push(fields.column_label.toString());
  }
}
var valueString = values.toString();
valueString = valueString.replace(/,/g, '\n');
gs.print(valueString);
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?