To address the behavior where changing the "Assignment Group" clears the "Assigned to" field and after saving the form it allows the "Assigned to" field to be editable again, you should refine the approach by utilizing both a Business Rule for server-side logic and a more sophisticated Client Script that can dynamically adjust based on the form state and field changes. Here's how you can tackle these nuances:
Business Rule
The Business Rule's purpose remains consistent: to track whether an initial assignment has been made. However, you’ll need to ensure it accounts for changes in the assignment group and maintains the "Assigned to" field as read-only if it has been previously filled.
Adjusted Business Rule Configuration
This Business Rule can remain similar to what was described earlier, essentially marking when an initial assignment has been made, but you should ensure it takes into account any logic specific to reassignments or group changes if needed.
Advanced Client Script Logic
You'll need a more complex Client Script that:
- Makes "Assigned to" read-only if an initial assignment has been made, accounting for the clearing of the "Assigned to" field when "Assignment Group" changes.
- Keeps track of whether the "Assignment Group" field was changed and then enforces the read-only state based on conditions.
Updated "onChange" Client Script for "Assignment Group"
This script now needs to handle cases where the "Assignment Group" changes, potentially clearing the "Assigned to" field but still enforcing it to be read-only under the right conditions.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
// Retrieves the custom flag value indicating if an assignment has been previously made
var initialAssignmentMade = g_form.getValue('u_initial_assignment_made');
if (initialAssignmentMade == 'true') {
// Delay execution to wait for other onChange scripts that may clear "Assigned to"
setTimeout(function() {
// If 'Assigned to' is clear after group change but an initial assignment was made, make it read-only
var assignedTo = g_form.getValue('assigned_to');
if (!assignedTo) {
g_form.setReadOnly('assigned_to', true);
}
}, 500); // Adjust timing as needed based on your instance's behavior
}
}
Ensuring Persistence After Save
Given that changing the "Assignment Group" clears the "Assigned to" and allows it to be editable upon saving, you'll need to ensure the form respects the initial assignment tracking.
On Form Load Script
An additional onLoad Client Script ensures the form loads with the correct field states based on existing conditions.
function onLoad() {
var initialAssignmentMade = g_form.getValue('u_initial_assignment_made');
// If an initial assignment has been made, ensure 'Assigned to' is read-only
if (initialAssignmentMade == 'true') {
g_form.setReadOnly('assigned_to', true);
}
}
Summary
The key enhancements here include a more sophisticated Client Script handling that adjusts to real-time changes ("onChange") and correct onLoad behavior to enforce field states when the form is reopened.
This approach requires careful testing, especially with the timing and interaction between different scripts and form states. Always validate changes in a non-production environment to ensure behavior aligns with operational expectations and user experience requirements.