Need to make a date field on a form business required only if a toggle has been changed from yes to no.
Cant use a business rule because that would make the date field mandatory even if the toggle wasn't changed (it was already on no)
Please help
Need to make a date field on a form business required only if a toggle has been changed from yes to no.
Cant use a business rule because that would make the date field mandatory even if the toggle wasn't changed (it was already on no)
Please help
Either you can use similar to my snippet without function name because it is inline function or you can follow this: carldesouza.com/.../
I am implementing it now, when adding event handler what shall I type in function field
Hello Morty,
As Abdul suggested the given BR will work. Please refer below BR where I have used date field as per your Requirement.
Thank You,
Amit Katariya
Have you tried using JS? That will work in your scenario
This doesn't meet the criteria because it will keep the date field mandatory even if the toggle was already at No
Hi MortySmith,
A business rule can do it for you.
Hi MortySmith,
You can use JavaScript to make a date field required if a toggle field changes from "Yes" to "No", but not from "No" to "Yes". Here's an example of how you can do this:
// Get references to the toggle and date fields var toggleField = formContext.getAttribute("togglefieldname"); var dateField = formContext.getAttribute("datefieldname"); // Set the date field as not required initially dateField.setRequiredLevel("none"); // Add an event listener to the toggle field toggleField.addOnChange(function(){ // Check if the toggle field has been changed to "No" if (toggleField.getValue() === false) { // Make the date field required dateField.setRequiredLevel("required"); } else { // If toggle field is not "No", set the date field back to not required dateField.setRequiredLevel("none"); } });
In this example, the script first gets references to the toggle and date fields by calling the formContext.getAttribute method and passing in the names of the fields. Then, it sets the date field as not required initially by calling the setRequiredLevel method and passing in the value "none".
Next, it adds an event listener to the toggle field by calling the addOnChange method on the toggle field. This listener will be triggered whenever the toggle field value is changed. Inside the listener, the script checks if the toggle field has been changed to "No" by calling the getValue method and comparing it with false. If the toggle field is "No", the script makes the date field required by calling the setRequiredLevel
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156