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

Sandeep Rajput
Tera Patron
Tera Patron

@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.parameter('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);
        }
    }

 

 

Hello @Sandeep Rajput,

Thank you very much for your help, really appreciated. 

Having followed your scripts and recommendations, it did work. I do however believe it is something that I may have missed.

 

Here's is a screenshot of the Script Include as I currently have it: 

 

Script Include.png

___________________________________________________________

Here's is a screenshot of the Client Script as I currently have it: 

 

Script Include.png

 ____________________________________________________________________

Thank you

@Hola Ola Sorry, I am confused here. Did the changes suggested by me work for you or not? Also, you shared screenshot of Script include twice. Could you please share the screenshot of client script too.

Good morning @Sandeep Rajput , 

My sincerest of apologies for the confusion. I didn't realize that I sent the Script Include twice. 

 

Here is the Screenshot of the Client Script: 

HolaOla_0-1724675002871.png

To answer your other question, No, it hasn't worked. But I'm sure it must me something I haven't done right.

 

I do appreciate your efforts though.

 

Thanks