- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-10-2025 12:22 AM
前回の質問に引き続き、参照変数についてご教示いただきたいです。
参照変数(A、B)を用意し、Aはsys_user_group、Bはsys_userを参照するようにしています。
BはAで指定したグループに所属するユーザーのみを参照させたいです。
実現させるためにはカタログクライアントスクリプトで、Aの値を取得し、Bのフィルター条件に挿入するイメージですが、スクリプトの設定方法をご教示いただきたいです。
現在のカタログクライアントスクリプトは以下の通りです。
UI Type:All
type:onchange
Variable name:A
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var grname = g_form.getValue('B');
var query;
var grmem = new GlideRecord('sys_user_grmember');
grmem.addQuery('group.name', grname);
grmem.query();
var usrIDs = [];
while (grmem.next()) {
usrIDs.push(grmem.user.sys_id.toString());
}
query = 'sys_idIN' + usrIDs.join(',');
query;
g_form.setValue('A', query);
}
解決済! 解決策の投稿を見る。
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-10-2025 12:41 AM
your onChange is on which variable and what is the type?
I assume your variable A is referring to Group table and variable B is referring to User table
if yes then update as this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '')
g_form.clearValue('B');
var grname = g_form.getValue('A');
var grmem = new GlideRecord('sys_user_grmember');
grmem.addQuery('group', grname);
grmem.query(function(gr) {
var usrIDs = [];
while (grmem.next()) {
usrIDs.push(grmem.user.sys_id.toString());
}
// You can now use usrIDs array as needed
g_form.setValue('B', usrIDs.toString());
});
}
If the group variable holds group name then simply update this line
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-11-2025 06:18 PM
Thank you for your response.
My apologies. It was my lack of knowledge.
I had assumed that getting a value from another reference variable was done using a catalog client script,
I have confirmed that it is also possible to set a filter on the reference variable.
Here is what I was able to implement
■[reference]-[Type Specifications]
・Reference:User[sys_user]
・Use reference qualifier:Advanced
・Reference qualifier:
javascript:
var query;
var value = current.variables.A;
var grmem = new GlideRecord('sys_user_grmember');
grmem.addQuery('group', value);
grmem.query();
var usrIDs = [];
while (grmem.next()) {
usrIDs.push(grmem.user.sys_id.toString());
}
query = 'sys_idIN' + usrIDs.join(',');
query;
※"A" is referring to Group variable.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-11-2025 08:45 PM
Sorry, I made a mistake.
I redid the answer selection.
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-11-2025 06:57 PM
Glad to know that my script helped.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader