Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Database viewに指定されたView tableのフィールドラベル名をスクリプトで取得

Yuya2009
Tera Contributor

GlideRecord('Database view name')を使用すると、Database viewのリスト画面にレコードが存在すれば、そのレコードのフィールドラベルを取得することが出来ますが、レコードが存在しない場合はフィールドラベルを取得することができないので困っています。
GlideReocrdを使用して、View Fieldに指定されたフィールドのカラムラベル名をView tableの設定から取得することは出来ますでしょうか?

5 REPLIES 5

Sagar Pagar
Tera Patron

Hi,

 

Try this scripts -

 

var sagar = new GlideRecord("database_view_name");
sagar.addQuery("add_your query");
sagar.query();
gs.info("count: " + sagar.getRowCount());  // it should print  - 1
if (sagar.next()) {
gs.info("Database view: " + sagar.getLabel());  // prints view label


gs.info("Field name: " + sagar.add_your_field_name.getLabel());  // prints column/field label

// Example -
gs.info("Incident short description label: " + sagar.inc_short_description.getLabel()); // prints short description column/field label


}

 

 

Thanks,
Sagar Pagar

The world works with ServiceNow

Dear Sagar

Thank you for your reply.

Does the above code work even if there is not a single record in the Database view?

I would like to know how to get the field label name specified in the View table even if there are no records in the Database View.

 

Best regards

 

Hi @Yuya2009,

 

No. It will not print the field label, if there is no records.

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi @Yuya2009,

Any updates on this? Kindly mark helpful and correct. It will be helpful for future readers.

 

Thanks,

Sagar Pagar

The world works with ServiceNow