make a field visible and mandatory if other field changes values

hadron_collider
Tera Contributor

Hello,

 

 

I am trying to make the field "Reject reason" visible and mandatory to fill in in order to change the status.

 

kata90_0-1704463611188.png

 

 

 

23 REPLIES 23

Change this into a client server ui action

Client & Server Code in One UI Action - ServiceNow Guru

 

in the client part use the code below

if(g_form.getValue('reject_reason')=='')
g_form.setMandatory('reject_reason', true);
-Anurag

@hadron_collider ,

 

Since you have the ui action as client side, you need to create a function in the script section.

 

refer this article - https://docs.servicenow.com/bundle/vancouver-api-reference/page/script/useful-scripts/reference/usin...

 

Please mark helpful if this helped.

 

Thanks,

@hadron_collider ,

 

 

function reject() {
  // Set the 'Incident state' and 'State' values to 'Resolved', and display mandatory fields
  if(g_form.getValue('u_reject_reason') == ''){
	g_form.setDisplay('u_reject_reason', true);
	g_form.setMandatory('u_reject_reason', true);
  return;
  }
  

  // Call the UI action and skip the 'onclick' function
  gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}

// Code that runs without 'onclick'
// Ensure call to server-side function with no browser errors
if (typeof window == 'undefined')
  serverResolve();

// Server-side function
function serverResolve() {
  current.update();
}

 

 

See if the above helps.

 

Thanks,

thanks for explanation but could you elaborate on this part: 

// Call the UI action and skip the 'onclick' function
  gsftSubmit(null, g_form.getFormElement(), 'resolve_incident'); //MUST call the 'Action name' set in this UI Action
}

 

Im not sure what is the purpose of the "Action Name"

Thank you in advance!

@hadron_collider ,

 

Add the action name here on the UI Action:

 

ahefaz1_0-1704492049802.png

 

 gsftSubmit(null, g_form.getFormElement(), 'your_ui_action_name');

 gsftSubmit(null, g_form. getFormElement(), "ui action id") triggers the UI Action which is specified in the 3rd parameter. Its like an auto click on the UI action.

Make sure action name does not have space. Something like "reject_approval_user"

 

Please mark helpful if this helped.

 

Thanks,