Database viewに指定されたView tableのフィールドラベル名をスクリプトで取得
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2022 07:44 PM
GlideRecord('Database view name')を使用すると、Database viewのリスト画面にレコードが存在すれば、そのレコードのフィールドラベルを取得することが出来ますが、レコードが存在しない場合はフィールドラベルを取得することができないので困っています。
GlideReocrdを使用して、View Fieldに指定されたフィールドのカラムラベル名をView tableの設定から取得することは出来ますでしょうか?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2022 08:33 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2022 08:09 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2022 12:16 AM
Hi @Yuya2009,
No. It will not print the field label, if there is no records.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2022 01:52 AM
Hi @Yuya2009,
Any updates on this? Kindly mark helpful and correct. It will be helpful for future readers.
Thanks,
Sagar Pagar