Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

client script on load using asynchronous

Anjali yadav1
Tera Contributor

pls tell the error in the coding as on running the script 

the email filed is undefined

@client scripts 

 

if (g_form.isNewRecord()) {
        g_form.setValue('u_caller', g_user.userID);
        var caller = g_form.getReference('u_caller', getCallerDetails);
        g_form.setValue('u_state', 'new');

        function getCallDetails(caller) {
            g_form.setValue('u_email', caller.email);
            g_form.setValue('u_location', caller.location);
            g_form.setValue('u_department', caller.department);
        }
    }
1 REPLY 1

Sandeep Rajput
Tera Patron
Tera Patron

@Anjali yadav1 

 

Here is the updated script, and it will work for you.

 

if (g_form.isNewRecord()) {
        g_form.setValue('u_caller', g_user.userID);
        var caller = g_form.getReference('u_caller', getCallerDetails);
        g_form.setValue('u_state', 'new');

        function getCallerDetails(caller) {
            g_form.setValue('u_email', caller.email);
            g_form.setValue('u_location', caller.location);
            g_form.setValue('u_department', caller.department);
        }
    }

 

In your code, on line number 3 you wrote name of callback function as getCallerDetails where as on line number 6 defined the function with name getCallDetails. Due to this the callback was failing.

 

Please mark the response helpful and accepted solution if it managed to address your issue.