Workspace onLoad scrip to create visible and mandatory field if Business Service 'Software' selected.

David168
Tera Expert

Hi Team!

I am working in the Agent Workspace area and am trying to recreate a UI scrip that functions in our ServiceNow UI however, in Agent Workspace, there seems to be some difficulty and thats why I am reaching out. 

On the incident table, if an Agent selects a Business Service (business_service) of Software, I need to show the software selction box (u_software) and make it mandatory.

I have this in a Client Script, sitting in the Agent Workspace application, Incident table, UI Type: All, Type: onLoad, and have Isolate script checked. 

find_real_file.png

My current code:

function onLoad() {
if(g_form.getDisplayBox('business_service').value == 'Software') {
g_form.setDisplay('u_software',true);
g_form.setMandatory('u_software',true);
}
else {
g_form.setDisplay('u_software',false);
g_form.setMandatory('u_software',false);
}
}

I cannot get this to work.  Perhaps someone out there can assist? 

Thanks;

Dave 

1 ACCEPTED SOLUTION

If you just remove the "if" that is checking isLoading you probably can skip the onLoad script.

View solution in original post

8 REPLIES 8

Claude D_
Tera Guru

I believe you have half the problem solved with the onLoad() client script. onLoad() will only make the visual changes when the form loads. onChange() is the other half of the problem and is a separate UI script.

onLoad() - Field has current value. Perform action.

onChange() - Field changes value. Perform action.

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

   if(g_form.getValue('field') == 'value'){
		g_form.setDisplay('field', true);
	} else {
		g_form.setDisplay('field', false);
	}
}

I believe you are right!  

Many thanks!  Sometimes I just can't see the forrest for the trees. 

I appreciate the help. 

If you just remove the "if" that is checking isLoading you probably can skip the onLoad script.

Thank you!  

This worked brilliantly.  Now I need to figure out how to mark both as correct!