Can I Auto-popluate a newly created field from the HR Profile?

Hola Ola
Giga Guru

Hello,

 

I am trying to auto-populate a form field (appraisal_due_date), based on the selected USER on a form that I'm developing for HR.

The field that I want to grab the information from is on the HR Profile. 

 

HolaOla_1-1724393912815.png

 

I can't seem to click on any of the HR Reference tables to dot-walk to that field.

 

Is there a way to bypass this?

 

HolaOla_0-1724393795199.png

 

Thank you

 

2 ACCEPTED SOLUTIONS

@Sandeep Rajput 

I'm trying to write a Script Include but it wouldn't save

Giving me this error message: Could not save record because of a compile error: JavaScript parse error at line (6) column (4) problem = missing } after property list

var getUserHRProfileInformation = Class.create();
getUserHRProfileInformation.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    type: 'getUserHRProfileInformation'

var getUserHRProfileInformation = Class.create();

getUserHRProfileInformation.prototype = Object.extendsObject(AbstractAjaxProcessor,{
getUsrActive: function()
{
var user = this.getParameter('sysparm_user');
var userGR = new GlideRecord('sn_hr_core_profile');
userGR.addQuery('sys_id',user);
userGR.query();
if(userGR.next())
{
return userGR.active;
}
else
return '';
},

});

View solution in original post

@Hola Ola 

Here is the updated script include. Make sure to create this script include in Human Resource: Core application scope. Otherwise it will not work.

 

 

var getUserHRProfileInformation = Class.create();
getUserHRProfileInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserHRProfileInformation: function() {
        var user = this.getParameter('sysparm_user');
        var gr = new GlideRecord('sn_hr_core_profile');
        gr.addQuery('user', user);
        gr.query();
        if (gr.next()) {
            return gr.getValue('u_appraisal_due_date');
        }
    },
    type: 'getUserHRProfileInformation'
});

 

 

 

Here is the onChange client script for the user field.

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    var abc = g_form.getValue('subject_person');
    var ga = new GlideAjax('global.getUserHRProfileInformation');
    ga.addParam('sysparm_name', 'getUserHRProfileInformation');
    ga.addParam('sysparm_user, abc);
    ga getXMLAnswer(getResponse)
    function getResponse(response) {
        g_form.setValue('appraisal_due_date',response);
        }
    }

 

 

 

 

View solution in original post

4 REPLIES 4

Sandeep Rajput
Tera Patron
Tera Patron

@Hola Ola In order to achieve this, you need to build a combination of an onChange client script + script include. You can pass the value of user id from the onChange client script using GlideAjax and on the server side, you can query the HR Profile of the selected user. From the HR Profile you can extract the appraisal_due_date and pass it on to the client side. This response can be populated on the due date variable on the catalog item

 

Hope this helps.

@Sandeep Rajput Thanks for your response. 
I'm however not proficient in writing codes/scripts. Any help or direction will be highly appreciated. 
Thanks

@Hola Ola 

Here is the updated script include. Make sure to create this script include in Human Resource: Core application scope. Otherwise it will not work.

 

 

var getUserHRProfileInformation = Class.create();
getUserHRProfileInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserHRProfileInformation: function() {
        var user = this.getParameter('sysparm_user');
        var gr = new GlideRecord('sn_hr_core_profile');
        gr.addQuery('user', user);
        gr.query();
        if (gr.next()) {
            return gr.getValue('u_appraisal_due_date');
        }
    },
    type: 'getUserHRProfileInformation'
});

 

 

 

Here is the onChange client script for the user field.

 

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    //Type appropriate comment here, and begin script below
    var abc = g_form.getValue('subject_person');
    var ga = new GlideAjax('global.getUserHRProfileInformation');
    ga.addParam('sysparm_name', 'getUserHRProfileInformation');
    ga.addParam('sysparm_user, abc);
    ga getXMLAnswer(getResponse)
    function getResponse(response) {
        g_form.setValue('appraisal_due_date',response);
        }
    }

 

 

 

 

@Sandeep Rajput 

I'm trying to write a Script Include but it wouldn't save

Giving me this error message: Could not save record because of a compile error: JavaScript parse error at line (6) column (4) problem = missing } after property list

var getUserHRProfileInformation = Class.create();
getUserHRProfileInformation.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    type: 'getUserHRProfileInformation'

var getUserHRProfileInformation = Class.create();

getUserHRProfileInformation.prototype = Object.extendsObject(AbstractAjaxProcessor,{
getUsrActive: function()
{
var user = this.getParameter('sysparm_user');
var userGR = new GlideRecord('sn_hr_core_profile');
userGR.addQuery('sys_id',user);
userGR.query();
if(userGR.next())
{
return userGR.active;
}
else
return '';
},

});