make a field visible and mandatory if other field changes values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:08 AM
Hello,
I am trying to make the field "Reject reason" visible and mandatory to fill in in order to change the status.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:30 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:35 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 06:40 AM - edited 01-05-2024 06:41 AM
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,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 01:52 PM
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-05-2024 02:03 PM
Add the action name here on the UI Action:
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,