Should not be able to click any UI action when field is empty

XYD23
Tera Contributor

Have a requirement that whenever field is empty I should not be able to click any UI actions available on the workspace level,

When it has some value in it then only I should be able to click

 

May I know what are the methods can we achieve this requirement?

11 REPLIES 11

Service_RNow
Mega Sage

Hi @XYD23 

Yes, you can have a single UI Action that runs both Client-Side and Server-Side code. This is necessary sometimes, for example in the case where you want to check additional conditions or gather additional information from the user After he clicks the UI Action but Before you pass control back to the server.

- Yes, the way it is done is fairly convoluted because both Client-Side and Server-Side script is defined in the very same script block; so only Some of the code applies Some of the time

RamSingh_0-1708490918389.jpeg

 

 

Use Below code:
function cancelPost(){  
  if (g_form.getValue('work_around') == ' '){
  g_form.showFieldMsg('work_around','MY ALERT MESSAGE');
  return false;  
  }  
  //Call the UI Action and skip the 'onclick' function  
  gsftSubmit(null, g_form.getFormElement(), 'post_kb'); //MUST call the 'Action name' set in this UI Action  
}  

1.  Check the "Client" checkbox.  Normally UI Actions run only on the server, so this checkbox tells ServiceNow to run this on the client instead.  But actually you will write both client-side and server-side code in the script block.

2.  Define a function which will be called ONLY when the UI Action is clicked.  (Not when it is rendered.)

3.  Give your action a name.  You will need to reference this name in the script itself.  Basically, the UI Action script will "call itself", but the 2nd time it is invoked, it will be run on the server, not the client.


Follow thread it will be helpful or More details:-

client-side-and-server-side-code-in-one-ui-action-using 

 

 

Please mark reply as Helpful/Correct, if applicable. Thanks!

Can you describe it more how and where exactly to use this code ?

I should not be able click any of ui action!!

Not one

Can you please share your code screenshot if it's possible?

 

XYD23_1-1708495844094.pngXYD23_2-1708495885317.png