I want to convert HR profile sys_id to sys_user sys_id

NaoyaT
Tera Expert

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);
    }
}

 

2 件の受理された解決策

@NaoyaT 

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.

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

元の投稿で解決策を見る

@NaoyaT 

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.

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

元の投稿で解決策を見る

7件の返信7

Ankur Bawiskar
Tera Patron
Tera Patron

@NaoyaT 

sorry your requirement is not clear.

Please share some screenshots

Your list collector refers to HR profile table and it's bringing the HR profile based on advanced ref qualifier

Your client script is setting single line text variable and appending it everytime the list collector is updated

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

@Ankur Bawiskar 

Sorry for the unclear question.

What we want to implement is that
“u_2303_va_userdel_bumongroup_target” in the first image is a list collector and specifies the user.
The “u_2303_va_userdel_bumongroup_target_Empnum” in the first image is the text, and when you specify a user above,
you want the employee number associated with that user to be automatically entered.

Example
1. Specify a user.
2. Auto-populate “employee_number:user_name”.

Then, when the request is submitted, we want it to appear as in the second image.

NaoyaT_0-1740530421664.png

 

Then, when the request is submitted, we want it to appear as in the second image.

NaoyaT_1-1740530496565.png

If the list collector references sys_user,
it can be implemented by catalog client scripts and script includes, but
if the list collector references sn_hr_core_profile, it will not work correctly.

@NaoyaT 

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.

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