error when trying to use client callable script include.

SarubalaC
Tera Contributor

SarubalaC_0-1747219259685.pngSarubalaC_1-1747219326632.pngSarubalaC_2-1747219445343.png

Hi,

 

My requirement is when the caller field changes in the incident table, user created email field should reflect the caller's email id. I am trying to do this using client callable script include. I am getting an error as shown in the second image. is there anything wrong in the code i have written. Please help me to rectify the error.(bottom most image is the clientscript.

6 REPLIES 6

Brad Bowman
Kilo Patron
Kilo Patron

Ensure you have only one Script Include with this name.  Add a gs.info line as the first line inside the getEmail to confirm the Script Include is running, then at the end to confirm a value is returned.  It's best practice to always return something from a SI to prevent unexpected results, so try something like var answer = 'false'; at the beginning, then set answer = gr.email.toString(); in the gr if block, return answer; at the end.

Chaitanya ILCR
Mega Patron

Hi @SarubalaC ,

 

update the script include make sure it return something

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

    getEmail: function() {
        var userId = this.getParameter('sysparm_callerid');
        if (!userId) return '';

        var userGR = new GlideRecord('sys_user');
        if (userGR.get(userId)) {
            return userGR.getValue('email');
        }
        return '';
    }

});

 

Client script

getXMLAnswer is easy to use I prefer it

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (newValue == '') {
        g_form.setValue('u_email', '');
        return;
    }

    var ga = new GlideAjax('updateCallerEmail');
    ga.addParam('sysparm_name', 'getEmail');
    ga.addParam('sysparm_callerid', newValue);
    ga.getXMLAnswer(function(response) {
        g_form.setValue('u_email', response);
    });

}

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

Ankur Bawiskar
Tera Patron
Tera Patron

@SarubalaC 

you can use onChange with getReference() callback and no GlideAjax, Script Include is required.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
    if (newValue == '') {
        g_form.clearValue('u_email');
    }
    var ref = g_form.getReference('caller_id', callBackMethod);
}

function callBackMethod(ref) {
    if (ref.email)
        g_form.setValue('u_email', ref.email);
}

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

@SarubalaC 

Hope you are doing good.

Did my reply answer your question?

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