Hi everyone,
I'm looking for guidance on implementing a field-level format validation in Creatio and wanted to check if there's a recommended no-code or low-code approach before going down the custom development route.
The requirement is as follows:
- We have a VAT Number text field on the Account (or Contact) page.
- For domestic customers, the value must follow the local VAT number format.
- For foreign (EU) customers, the value must follow the EU VAT number format: 2 letters followed by at least 6 digits (e.g., XX12345678).
- The correct format to validate against should depend on the value of the Country field on the same record.
What I'd like to achieve:
- When a user enters a VAT number that doesn't match the expected format for the selected country, the system should show a validation error and prevent saving.
My questions:
1. Is there a way to implement pattern/regex-based validation like this using Business Rules or Process Designer, without writing custom code?
2. If not, what would be the recommended approach, client-side field validation (JS), server-side entity validation, or a business process with a Formula element?
3. Has anyone implemented something similar (country-dependent format validation) and would be willing to share their approach?
Any guidance, examples, or links to relevant documentation would be greatly appreciated.
Thanks in advance!
Like
You could do this in an EntityEventListener class if you want to ensure on the back end that a record cannot be added with an incorrectly formatted value, see https://customerfx.com/article/adding-code-to-listen-for-entity-events-in-creatio/
However, you could do it in page code as a validation step pretty easily to validate before saving. To do this, you'd override/handle the save request on the page, do the validation, and then either allow or prevent the save from happening. See here for handling the save: https://customerfx.com/article/adding-code-to-the-save-event-of-a-creatio-freedom-ui-page/
Once you validate, if you don't want the save to occur (if it fails your validation) then just return false instead of return next.handle(request);
You could do this on the change of the field as well, see https://customerfx.com/article/responding-to-an-event-when-a-field-is-changed-on-a-creatio-freedom-ui-page/ however, that could be tricky since the change will fire for each keypress. You could alternatively handle the blurred request of the field so you validate on the exiting of the field, see https://community.creatio.com/questions/which-are-events-field-can-be-handled-freedomui. That could complicate what to do if it fails validation. Handling the save and validating there would be the most straightforward approach.
Also, just to mention, you could also use a validator for this as well, which would be the most technically correct approach for handling on the page, see https://academy.creatio.com/guides/dev/development-on-creatio-platform/8.3/platform-customization/freedom-ui/customize-page-fields/examples/implement-the-field-value-validation. Although you'd need some tricks for getting other field values (the selected country) in the validator. There are some posts in the community forums about how to workaround that in a validator.
Ryan
Hello,
You can follow the potential solutions outlined in the comment above.
In general, implementing this type of custom validation using a regular expression requires custom development.
The recommended options are:
- Backend validation, for example by implementing the validation logic in an Entity Event Listener.
- Client-side validation, by overriding the save request on the page and performing the validation before the record is saved.
Both approaches are valid, and the most appropriate option depends on your specific business requirements and where you would like the validation to be enforced.
No-code backend validation has been a long-time feature wishlist item for me. Entity Event Listeners is what we tend to opt for when required, but it isn't the simplest.