How to query HR profile field value from a Transform entry script of a 'sys_user' Target table

savitha5
Tera Contributor

Hi All,

We have a requirement to set a sys_user account to Active/Inactive using a Web service Transform map based on the field Date Hired from source table.

There are chances that the Date Hired will be imported as empty from source table. In such case, we want to validate the Employment Start Date of the user's HR Profile record (from sn_hr_core_profile) and set the sys_user profile to active if it is a future date, if it is not and it is already active then no action required. Since we don't have the Date field on sys_user table directly, I am trying to use Script include on HR scope and GlideAjax on my transform map entry script (Global scope).

 

Can anyone tell me how to achieve this. How to call a Scoped application script include on Transform map entry script. My script include is not triggered at all 😞 .

I have also shared my scripts below:
Script include:

var hr_StartDate = Class.create();
hr_StartDate.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
    getHRempStartDate: function() {
        var emp_id = this.getParameter('sysparm_emp_id');
        
        var hr_profile_gr = new GlideRecordSecure('sn_hr_core_profile');
        hr_profile_gr.addQuery('employee_number', emp_id);
        hr_profile_gr.addQuery('user.active', 'true');
        hr_profile_gr.query();
        gs.log('script include query: '+ hr_profile_gr.employee_number);
        if (hr_profile_gr.next()) {
        //    hr_profile_gr.next();
            var user_detail = hr_profile_gr.employment_start_date;
            gs.log('Emp start date on Script include: '+user_detail);
            return user_detail;
        }
    },
});

Transform map entry script :
Source table: My import set table
Use source script: true
Target table: sys_user
Target field: Active
Script:
var DateHired;
            var todayDt = new GlideDate();
            if (source.u_employee_active_inactive == "no") {
                if (source.u_date_hired == "") {

                    //DateHired = new GlideDate();
                    gs.log("Test DateHired " + DateHired);
                    var empno = source.u_personnel_number;
                    //**if no Date hire value then check for the user profile under HR Profile
                    gs.log("Emp no: " + empno);
                    var ga = new GlideAjax('sn_hr_core.hr_StartDate');
                    ga.addParam('sysparm_name', 'getHRempStartDate');
                    ga.addParam('sysparm_emp_id', empno);
                    ga.getXML(parseUserResponse);
                }
            }

            function parseUserResponse(response) {
                var user_detail = response.responseXML.getElementsByTagName("user_detail");
                gs.log('Employee start date: ' + user_detail);
                DateHired.setDisplayValue(user_detail, "dd-MMM-yyyy");
                gs.log('Hired date: '+DateHired);
                if (DateHired > todayDt) {
                    return "true";
                }
}

5 REPLIES 5

Paul has good points as well.  Scope is usually the next step I would reviewed.