- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 07:59 AM
UI Policy to prevent Form Submission when Selected Fields are not Populated - from All (Core UI, Service Portal etc) views
Hi guys,
How can I write a UI Policy which prevents a user from submitting a form (either via Core UI or Service Portal views), unless all/specific Fields are populated.
Please see my screenshots attached.
I have 3 Fields: Building (u_building), Floor (u_floor) and Space (u_space) as well as a Location Not Found? Checkbox.
These are not Mandatory Fields and I need to leave them as Not Mandatory on the Form itself.
However, I want that the User has to populate at least one of the fields Building, Floor, Space or if they check Location Not Found?, a new box pops up called Location Detail (u_location_detail) and they will have to at least complete that box.
Basically I don't want users submitting the Form, with blank Location data. It has to either have data in either one of the Building, Floor or Space fields or if Location Not Found? = True, the user then has to enter data in the Location Detail field, before a Form can be saved/submitted.
How can I set this up - is it via a UI Policy and what would that look like?
Many thanks guys - always appreciate the help.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 08:12 AM
Hi @WazzaJC
You need to write a on submit client script with code like below
function onSubmit() {
var building = g_form.getValue('u_building');
var floor = g_form.getValue('u_floor');
var space = g_form.getValue('u_space');
var locationNotFound = g_form.getValue('u_location_not_found');
var locationDetail = g_form.getValue('u_location_detail');
if ((!building || !floor || !space) && (!locationNotFound || !locationDetail)) {
alert('Please provide location information before submitting the form.');
return false;
}
return true; // Allow form submission
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 08:37 AM
Try this then
function onSubmit() {
var building = g_form.getValue('u_building');
var floor = g_form.getValue('u_floor');
var space = g_form.getValue('u_space');
var locationNotFound = g_form.getValue('location_not_found');
var locationDetail = g_form.getValue('u_location_detail');
// Check if either Building is populated, or Building and Floor are populated,
// or Building, Floor, and Space are populated, or Location Not Found with Location Detail filled
if ((building && !floor && !space) ||
(building && floor && !space) ||
(building && floor && space) ||
(locationNotFound && locationDetail)) {
return true; // Allow form submission
} else {
// Display an error message to the user
alert('Please provide at least one valid location data combination.');
return false; // Prevent form submission
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 10:16 AM - edited 06-21-2023 10:16 AM
You can create the same onSubmit Client Script on the Record Producer and it will work.
Just make sure to change the variable names in the code if they are different in the record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 10:12 AM
Hello Manmohan,
Is it possible to use this same Client Script on a Record Producer also ?
I have a Record Producer (A Catalog Item called Report an Issue).
It has variables for Building, Floor and Space and then takes those field values and populates to the Incident Form, after submission of the Report an Issue Catalog Item.
How can I get this same onSubmit Client Script to work on the Catalog Item ?
Many Thanks once again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 10:16 AM - edited 06-21-2023 10:16 AM
You can create the same onSubmit Client Script on the Record Producer and it will work.
Just make sure to change the variable names in the code if they are different in the record producer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 11:50 AM
Hi Manmohan, thank you again.
Would the script still be using g_form if it trying to get the values of the Variables from a Variable Set ?
So don't I need to update the Script to look & fetch the value in the Variable field which is on the Variable Set ?
So example - the Variable Names are: Building, Floor, Space and they are on a Variable Set called Location Data Common Variables.
I am not sure if the g_form works - do I need to change ?
Many thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2023 01:13 PM
Hi Manmohan,
Thanks very much. You are indeed correct. I applied the Client Script to the Record Producer and it works perfectly! I just had to ensure the Variable Names were correct in the code, then all works perfectly! Thank you once again, really appreciate your help today.
Kind Regards.