グループに紐づくロールを参照・選択/Browse and select roles associated with the group

NaoyaT
Tera Expert

ご教示いただけますと幸いです。

参照フィールドでグループを選択すると、そのグループに紐づいているロールをリストコレクタフィールドで選択できるようにする方法はありますでしょうか。

また、リストコレクタフィールドでロールを選択すると、日付で表示されてしまうためロール名で表示したいのですが、
ロールテーブル側の表示設定ではなく、カタログUIポリシーやカタログクライアントスクリプト等で実装したいと考えております。(ロールテーブルがOOTBのため。)

 

-------------

 

We would appreciate it if you could enlighten us.

 

Is there a way to select a group in the reference field so that the roles associated with that group can be selected in the list collector field?

Also, when I select a role in the list collector field, it is displayed by date and I would like to display it by role name,
We would like to implement this in a catalog UI policy, catalog client script, etc., rather than in the display settings on the role table side.

1 件の受理された解決策

Ankur Bawiskar
Tera Patron
Tera Patron

@NaoyaT 

so you will select group as reference variable and then show roles associated with that group in list collector

then do this

1) list collector variable referring to sys_user_role

2) advance ref qualifier as this in that variable

javascript:
var arr = [];
var gr = new GlideRecord("sys_group_has_role");
gr.addQuery("group", current.variables.groupVariableName);
gr.query();
while (gr.next()) {
   arr.push(gr.getValue('role'));
}
return 'sys_idIN' + arr.toString();

3) also in the list collector variable add this in attributes so that Role Name, Role Created on shows when user types in

Also remember to use ref_qual_elements=groupVariableName so that ref qualifier works fine.

ref_auto_completer=AJAXTableCompleter,ref_ac_columns=sys_created_on,ref_ac_columns_search=true,ref_ac_order_by=name,ref_qual_elements=groupVariableName

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

元の投稿で解決策を見る

7件の返信7

J Siva
Tera Sage

Hi @NaoyaT 

You can achieve this by creating one client callable script include & advanced ref qualifier in the catalog variable (list collector).

You can the below community post to get some idea.

https://www.servicenow.com/community/developer-forum/get-group-based-on-role-from-sys-group-has-role...

Once you create the script include, you need to call that by passing the group sys id from the list collector type field reference qualifier.

Let me know if you have any queries.

Regards,

Siva

senon
Tera Sage

こんにちは。参考程度ですが共有いたします。
残念ながら、表示値を[sys_group_has_role]テーブル内の表示値を変更せずに、変数の表示を変更する場合をなさそうに思えます。


変数の属性(attribute)を加えることで、検索時のサジェストにロール名を表示することは可能です。
しかし、選択時に表示されるのは定義された表示値になるので、全般的な改善にはならないでしょう。

必要な属性は3つです。

  • ref_auto_completer=AJAXTableCompleter
  • ref_ac_columns=<表示したいフィールド>
  • ref_ac_columns_search=true

senon_0-1743992852889.png

senon_1-1743994662682.png



参考になりそうなcommunityのスレッドを共有します。
解決済み: 参照の表示値をどのように変更しますか... - ServiceNow Community
解決済み: Table without a value to display - ServiceNow Community
参照変数に複数の列値を表示する - ServiceNow Community
変数属性が機能しないref_ac_columns - 2ページ - ServiceNow Community
解決済み: Catalog Item : Change display value for each value... - ServiceNow Community
解決済み: カタログアイテムの変数の表示値を変更する... - ServiceNow Community

 

Ankur Bawiskar
Tera Patron
Tera Patron

@NaoyaT 

so you will select group as reference variable and then show roles associated with that group in list collector

then do this

1) list collector variable referring to sys_user_role

2) advance ref qualifier as this in that variable

javascript&colon;
var arr = [];
var gr = new GlideRecord("sys_group_has_role");
gr.addQuery("group", current.variables.groupVariableName);
gr.query();
while (gr.next()) {
   arr.push(gr.getValue('role'));
}
return 'sys_idIN' + arr.toString();

3) also in the list collector variable add this in attributes so that Role Name, Role Created on shows when user types in

Also remember to use ref_qual_elements=groupVariableName so that ref qualifier works fine.

ref_auto_completer=AJAXTableCompleter,ref_ac_columns=sys_created_on,ref_ac_columns_search=true,ref_ac_order_by=name,ref_qual_elements=groupVariableName

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@NaoyaT 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader