- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-25-2025 12:03 AM
I have a catalog item list collector variable that references the HR profile table and
allows me to specify a user.
We would like to use Catalog Client Script and Script Include
to add a process to link the user name and employee number based on the sys_id information of the specified user and put it into single line text.
The Catalog Client Script and Script Include functionality is proven in the sys_user table in the list collector variable.
Therefore, I would like to convert the sys_id of the HR profile to the sys_user's sys_id.
Is it possible to set it in the Reference qualifier of the list collector variable?
Or do I need to set it in the catalog client script?
*Script include is a common setting and cannot be changed.
The current list collector variable has the following settings
List table:HR Profile [sn_hr_core_profile]
Reference qualifier
javascript:
var dep = new GlideRecord('cmn_department');
var qc =dep.addQuery('u_ou', 'CONTAINS', 'S99999999999');
qc.addOrCondition('u_ou', 'CONTAINS', 'H00000000000');
dep.query();
var DeptIds = [];
while (dep.next()) {
DeptIds.push(dep.getValue('u_ou'));
}
'user.department.u_ouIN' + DeptIds;
The current catalog client script has the following settings
type:onchange
variable name:hr_profile_list_collector
Script
type:onchange
variable name:hr_profile_list_collector
Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
g_form.setValue('employee_number_single_line_text', '');
if (newValue == '') {
return;
} else {
var ajax = new GlideAjax('script_include_name');
ajax.addParam('sysparm_name', 'getUserFromSysid');
var wk_id = newValue.split(',');
for (var i = 0; i < wk_id.length; i++) {
ajax.addParam('sysparm_user_sysid', wk_id[i]);
ajax.getXML(_getUserInfo); //関数呼び出し
}
return;
}
function _getUserInfo(response) {
var str_col_nam = 'employee_number_single_line_text';
var result_value = '';
var user_data = JSON.parse(response.responseXML.documentElement.getAttribute('answer'));
if (user_data.result && user_data.record.user_name != '') {
if (g_form.getValue(str_col_nam) == '') {
result_value = user_data.record.user_name + ':' + user_data.record.name;
} else {
result_value = ',' + user_data.record.user_name + ':' + user_data.record.name;
}
} else {
if (g_form.getValue(str_col_nam) == '') {
result_value = 'NotFound';
} else {
result_value = ',NotFound';
}
}
g_form.setValue(str_col_nam, g_form.getValue(str_col_nam) + result_value);
}
}
解決済! 解決策の投稿を見る。
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-25-2025 07:01 PM
if list collector refers to HR profile then you can use onChange with Catalog client script and bring the employee number and add them as comma separated values
Something like this
Script Include: It should be client callable
var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkRecordPresent: function() {
var id = this.getParameter('sysparm_hrprofiles');
var arr = [];
var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('sys_id', 'IN', id);
gr.query();
while (gr.next()) {
arr.push(gr.user.employee_number.toString());
}
return arr.toString();
},
type: 'checkRecords'
});
Client script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var ga = new GlideAjax('checkRecords');
ga.addParam('sysparm_name', "checkRecordPresent");
ga.addParam('sysparm_hrprofiles', g_form.getValue('u_2303_va_userdel_bumongroup_target'));
ga.getXMLAnswer(function(answer) {
if (answer != '') {
g_form.setValue('u_2303_va_userdel_bumongroup_target_Empnum', answer);
}
});
//Type appropriate comment here, and begin script below
}
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-26-2025 10:53 PM
yes
update this line
arr.push(gr.user.employee_number.toString() + ':' + gr.user.user_name.toString());
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-26-2025 10:40 PM
Thank you for your response.
With the script include and catalog client script you taught me,
I was able to get the employee number associated with the selected user as shown in the image.
If possible, I would like to use “employee number: user name”. Is it possible to set this up?
- 新着としてマーク
- ブックマーク
- 購読
- ミュート
- RSS フィードを購読する
- ハイライト
- 印刷
- 不適切なコンテンツを報告
02-26-2025 10:53 PM
yes
update this line
arr.push(gr.user.employee_number.toString() + ':' + gr.user.user_name.toString());
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-27-2025 12:25 AM
Thank you for your response.
I was able to display “employee number: user name”.
It was very helpful. Thank you very much.