- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 11:25 PM
I have a development task wherein a user can choose a date in custom date field, only if the conditions below are met
1. case status is equals to complete or completed
2. choice field A or choice field B is not empty
How can I achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 11:53 PM
YOu can add the error message as well:
var caseStatus = g_form.getValue('state');
var choiceA = g_form.getValue('choice_field_a');
var choiceB = g_form.getValue('choice_field_b');
// Get the custom date field
var customDateField = g_form.Value('custom_date_field');
// Check if case status is complete or completed and either choice field A or B is not empty
if ((caseStatus == 'complete' || caseStatus == 'completed') && (choiceA || choiceB)) {
// Enable the custom date field
g_form..setReadOnly('customDateField',false);
} else {
// Disable the custom date field if the conditions are not met
g_form.addErrorMessage('Date can not be selected')
// Clear the value to prevent submitting invalid data
g_form.clearValue('custom_date_field');
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2024 10:04 PM
if (caseStatus != '1' || caseStatus != '2') -
This condition states: "If caseStatus is not equal to '1', or caseStatus is not equal to '2', then...". The problem with this logic is that it will always evaluate to true because caseStatus cannot be both '1' and '2' at the same time.
To fix this, you should use the logical operator && (logical AND) instead of || (logical OR) in your condition.
if (caseStatus != '1' && caseStatus != '2')
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 11:41 PM
I think you can write onchange client script on custom date field, below is the sample script you can use:
var caseStatus = g_form.getValue('state');
var choiceA = g_form.getValue('choice_field_a');
var choiceB = g_form.getValue('choice_field_b');
// Get the custom date field
var customDateField = g_form.Value('custom_date_field');
// Check if case status is complete or completed and either choice field A or B is not empty
if ((caseStatus == 'complete' || caseStatus == 'completed') && (choiceA || choiceB)) {
// Enable the custom date field
g_form..setReadOnly('customDateField',false);
} else {
// Disable the custom date field if the conditions are not met
g_form..setReadOnly('customDateField',true);
// Clear the value to prevent submitting invalid data
g_form.setValue('custom_date_field', '');
}
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 11:43 PM
Hi Therese,
I would create a UI Policy on the date field, making it either readonly, or hide it till these conditions are met.
something like below for UI action:
and then create ui policy action for date field:
Please mark this answer correct if you find it usefull.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 11:46 PM
The Custom Date field should always be editable and visible. The requirement is to add an error if conditions are not met.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-07-2024 11:53 PM
YOu can add the error message as well:
var caseStatus = g_form.getValue('state');
var choiceA = g_form.getValue('choice_field_a');
var choiceB = g_form.getValue('choice_field_b');
// Get the custom date field
var customDateField = g_form.Value('custom_date_field');
// Check if case status is complete or completed and either choice field A or B is not empty
if ((caseStatus == 'complete' || caseStatus == 'completed') && (choiceA || choiceB)) {
// Enable the custom date field
g_form..setReadOnly('customDateField',false);
} else {
// Disable the custom date field if the conditions are not met
g_form.addErrorMessage('Date can not be selected')
// Clear the value to prevent submitting invalid data
g_form.clearValue('custom_date_field');
}
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Thanks