Hi all,
In case page I have two lookup fields - Owner and Individuals both are lookups on contacts.
Validation required - They should not accept same values.
How can I achieve this. Please help.
Many thanks.
Like
Hello,
You can enforce this entirely on the client side in Freedom UI. The two most reliable approaches are a save handler (crt.SaveRecordRequest) and a custom validator (inline error message as the user fills the form). You can use either of these
Example - Save handler (blocks the save)
handlers: /**SCHEMA_HANDLERS*/[
{
request: "crt.SaveRecordRequest",
handler: async (request, next) => {
const owner = await request.$context.Owner;
const individuals = await request.$context.Individuals;
if (owner && individuals && owner.value === individuals.value) {
request.$context.executeRequest({
type: "crt.ShowDialogRequest",
$context: request.$context,
dialogConfig: {
data: {
message: "Owner and Individuals cannot be the same contact.",
actions: [
{ key: "ok", config: { color: "primary", caption: "OK" } }
]
}
}
});
return; // stops the save
}
return next?.handle(request);
}
}
]/**SCHEMA_HANDLERS*/
Custom Validator: Define a custom validator on either field in the ViewModelConfig, then trigger it via the attribute change request whenever either field's value changes.
- Using both is a common pattern: validator for live feedback, save handler as a safety net.
Hello,
As mentioned above, this functionality can be achieved by implementing custom logic within the crt.SaveRecordRequest handler, which allows you to prevent the data from being saved when necessary conditions are not met.
Alternatively, you may consider implementing a custom validator.
For your reference, the following articles may be helpful:
"handlers" schema section | Creatio Academy
Implement the validation of a field value on a page | Creatio Academy