Client Script in Agent Workspace

ericpetty
Tera Contributor

I have a requirement based on work we did on the New Call module (we are transitioning to Agent Workspace). We have an onChange client script that fills a custom field (u_workstation) which looks up the caller ID from the cmdb table and fills it, if it is empty. This works perfectly on the New Call, and even works on the platform version (default view) of Interaction records. *I have tried this as Mobile/Service Portal and All, with no change in behavior

**Additional note: on New Call the user field is called 'caller' instead of 'opened_for' but otherwise these scripts are identical.

function onChange(control, oldValue, newValue, isLoading) {
   //If the page isn't loading
   if (!isLoading) {
      //If the new value isn't blank
      if(newValue != '') {
         //check to see if we have a workstation listed
         var ci = g_form.getValue('u_workstation');
          if(ci == ''){
	    var user = g_form.getValue('opened_for'); //get the current user
    	    var gr = new GlideRecord('cmdb_ci_computer'); //Table your computers reside in
            gr.addQuery('assigned_to', user);
            gr.query();
            if(gr.next()){
               g_form.setValue('u_workstation', gr.sys_id);
            }
         }
      }
   }
}
1 ACCEPTED SOLUTION

Jace Benson
Mega Sage

If I recall correctly, Agent workspace should work exactly like SP scripts.  Meaning that you can't just do a GlideRecord call that way.  Really you should probably be doing a glideAjax call but.. this should get it working.

https://docs.servicenow.com/bundle/newyork-application-development/page/app-store/dev_portal/API_ref...

function onChange(control, oldValue, newValue, isLoading) {
   //If the page isn't loading
   if (!isLoading) {
      //If the new value isn't blank
      if(newValue != '') {
         //check to see if we have a workstation listed
         var ci = g_form.getValue('u_workstation');
          if(ci == ''){
	    var user = g_form.getValue('opened_for'); //get the current user
    	    
            var comp = new GlideRecord('cmdb_ci_computer');
            comp.addQuery('assigned_to', user);
            comp.query(function(compRec){
              if(compRec.next()){
                g_form.setValue('u_workstation', compRec.sys_id);
              }
            });
            
         }
      }
   }
}

View solution in original post

1 REPLY 1

Jace Benson
Mega Sage

If I recall correctly, Agent workspace should work exactly like SP scripts.  Meaning that you can't just do a GlideRecord call that way.  Really you should probably be doing a glideAjax call but.. this should get it working.

https://docs.servicenow.com/bundle/newyork-application-development/page/app-store/dev_portal/API_ref...

function onChange(control, oldValue, newValue, isLoading) {
   //If the page isn't loading
   if (!isLoading) {
      //If the new value isn't blank
      if(newValue != '') {
         //check to see if we have a workstation listed
         var ci = g_form.getValue('u_workstation');
          if(ci == ''){
	    var user = g_form.getValue('opened_for'); //get the current user
    	    
            var comp = new GlideRecord('cmdb_ci_computer');
            comp.addQuery('assigned_to', user);
            comp.query(function(compRec){
              if(compRec.next()){
                g_form.setValue('u_workstation', compRec.sys_id);
              }
            });
            
         }
      }
   }
}