Check the length of the string before saving the record

Hello, please advise me how to use a script to check the length of the entered string before saving the record, or not to save the record if the item has less than 10 characters. This check only needs to be done if another entry takes a certain value and the checked entry is less than 10 characters. I have a record that I pre-populate with the same 5 characters for the user at the beginning, because they are always the same. I want the user to fill in the remaining characters of this string. If he doesn’t fill them in, I want to warn him.

I wanted to do this check in the Pre-Save section of the script below:

if (doo.model.typePOS.value === ‘Existing POS’ && doo.model.cisloPOS.value.length < 10) { doo.alert.showError(‘POS item number is not filled in correctly!’,‘POS number should have 10 digits total.’); }; }.

The check passes, the message is displayed, but I don’t know how to ensure that the record cannot be saved until the user enters the checked item correctly.

Thank you. Milan

Hi,
use

doo.model.isValid = false;

Regards
Michal

Hello, thank you. I’ve added the following to the script:

if (doo.model.typePOS.value === ‘Existing POS’ && doo.model.cisloPOS.value.length < 10) { * * doo.alert.showError(‘Item POS number is not filled in correctly!’,‘POS number should have 10 digits in total.’); * * doo.model.isValid = false;* * }*

The record is not saved, the record detail window remains displayed, but if I add the required number of characters in the checked item and then press the save button, the window remains displayed and nothing else happens, that is, the record is not saved either. I can only close the window without saving the changes.

Milan

Hello,
You need to setup the model validity back in case the model is valid for saving

doo.model.isValid = true;

Regards
Michal

Thanks a lot for the advice Michal, it’s working as it should :+1: :slightly_smiling_face:

Regards
Milan