On change Client script not working inside Service Operations Workspace

gnewuser
Tera Contributor

I have a user select box on which there is a on change which would load the location, phoen number etc. It works in the platform view but not on the Service Operations workspace.

Both Isolate script is checked true and UI type is set to "All"

 

Following is the code. any pointers appreciated.

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading)
        return;
 var userSysId = newValue;
var userGR = new GlideRecord('sys_user');
    if (userGR.get(userSysId)) {
        // If the user record is found, populate the location and phone number fields
		g_form.addInfoMessage("inside");
        g_form.setValue('location', userGR.getValue('location'));
		g_form.setValue('u_business_phone',userGR.getValue('phone'));
	}

}
1 ACCEPTED SOLUTION

Amit Verma
Kilo Patron
Kilo Patron

Hi @gnewuser 

 

We can't do a Glide Query through a client script directly, you need to make use of GlideAjax or g_form.getReference() APIs to achieve this. Refer below post and set it up :

https://www.servicenow.com/community/developer-forum/workspace-client-script-calling-script-include/...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

View solution in original post

4 REPLIES 4

Community Alums
Not applicable

Hi @gnewuser ,

Try with g_user.userID.

 

Bhavya11
Kilo Patron

Hi @gnewuser ,

 

you can try something like below

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    //Type appropriate comment here, and begin script below

    var caller = g_form.getReference('caller_id', getCallerInfo);

    function getCallerInfo(caller) {
		alert("inside");
        g_form.setValue('description', caller.email);
        g_form.setValue('location', caller.location);
        g_form.setValue('business_phone', caller.phone);
    }
}

 

 

Note :Gliderecord should not be used in client side scripting and can be easily replaced/remodeled using a script include + Glideajax

 

 

 

Please mark helpful & correct answer if it's really worthy for you.

 

Thanks,

BK

 

Sandeep Rajput
Tera Patron
Tera Patron

@gnewuser Direct GlideRecord queries are not supported on Service Portal and Workspace client script, you need to use GlideAjax/g_form.getReference to replace the following code

var userGR = new GlideRecord('sys_user');
    if (userGR.get(userSysId)) {

Please refer to https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0694090 to know more about this topic.

Amit Verma
Kilo Patron
Kilo Patron

Hi @gnewuser 

 

We can't do a Glide Query through a client script directly, you need to make use of GlideAjax or g_form.getReference() APIs to achieve this. Refer below post and set it up :

https://www.servicenow.com/community/developer-forum/workspace-client-script-calling-script-include/...

 

Thanks and Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.