Can someone please help me clean up these scripts?

Hola Ola
Giga Guru

Hello,

I know that what I've written is a bunch of nonsense, but I am horrible at scripting and I would really like some help.

 

My goal is , once I type in a User (subject_person) to auto-populate my form field (appraisal_due_date) with the information that is on the HR Profile (u_appraisal_due_date). 

 

HolaOla_0-1724458961765.png

 

Pertinent Information:

Name of my Script Include: getUserHRProfileInformation

Name of HR Profile: sn_hr_core_profile

Name field on HR Profile: user

 

Here is the Nonsense the I have:

_____________________________________________________________________

Script Include: 

var getUserHRProfileInformation = Class.create();
getUserHRProfileInformation.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getUserHRProfileInformation: function() {
        var y = this.parameter('user');
        var gr = new GlideRecord('sn_hr_core_profile');
        gr.addQuery('sys_id', 'user');
        gr.query();
        if (gr.next()) {
            return gr.u_first_name + ';' + gr.u_last_name + ';' + gr.u_appraisal_due_date;
        }
    },
    type: 'getUserHRProfileInformation'
});
 __________________________________________________________________
CLIENT SCRIPT: On-change
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');
    function pop(response) {
        g_form.setValue('appraisal_due_date');
        }
    }
 
Any help/assistance will be greatly appreciated.
 
Thank you
1 ACCEPTED SOLUTION

@Hola Ola Please try the following version.

 

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('sn_hr_core.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

7 REPLIES 7

@Hola Ola My bad, I shared an incorrect client script earlier. Please try the following and see if it works.

 

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('sn_hr_core.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 ,

It is giving an Error

HolaOla_0-1724677529313.png

 

@Hola Ola Please try the following version.

 

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('sn_hr_core.getUserHRProfileInformation');
    ga.addParam('sysparm_name', 'getUserHRProfileInformation');
    ga.addParam('sysparm_user', abc);
    ga.getXMLAnswer(getResponse);

    function getResponse(response) {
        g_form.setValue('appraisal_due_date', response);
    }
}