How to make field mandatory based upon view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2023 10:40 PM
Hello Team,
I have 2 fields I want to make mandatory based upon different different view. and also want to make mandatory on workspaces. How can I achieved that?
@Community Alums
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 05:16 AM
Hello,
Depending on how you are making the view mandatory, if it is UI policy or client script you will have the option to write it for a specific view using the view field. Mark the global as false you will then see the field to write the view name:-
Client script:-
Ui policy:-
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2023 08:50 AM
HI @taylor13 ,
I trust you are doing great.
Identify the view or workspace where you want to make fields mandatory.
Locate the client script associated with that view or workspace. This can be done by navigating to "System Definition" -> "Client Scripts" and filtering by the appropriate table and view.
Create a new client script or modify the existing one, and add the following code:
function onSubmit() {
// Check the current view or workspace
var currentView = g_form.getViewName();
// Check if the mandatory fields should be enforced for this view or workspace
if (currentView == 'your_view_name' || currentView == 'your_workspace_name') {
// Get the values of the fields you want to make mandatory
var field1Value = g_form.getValue('your_field1_sys_id');
var field2Value = g_form.getValue('your_field2_sys_id');
// Perform validation and display error messages if the fields are empty
if (field1Value == '') {
g_form.showFieldMsg('your_field1_sys_id', 'This field is mandatory', 'error');
return false; // Prevent the form submission
}
if (field2Value == '') {
g_form.showFieldMsg('your_field2_sys_id', 'This field is mandatory', 'error');
return false; // Prevent the form submission
}
}
// Allow the form submission if the fields are not mandatory or have values
return true;
}
Replace 'your_view_name' with the actual name of the view where you want to enforce the mandatory fields. Similarly, replace 'your_workspace_name' with the actual name of the workspace.
Replace 'your_field1_sys_id' and 'your_field2_sys_id' with the actual sys_ids of the fields you want to make mandatory. You can find the sys_id of a field by inspecting its HTML element on the form.
Save the client script.
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi