The reason why it doesn't work is because the name is not constructed yet therefore the name value is null at this stage as it is not provided by UI, in order to solve this issue, here is what you need to use in API Before Save Script, a simple trick will work:
PHP Code:
if (entity\isNew() && !recordService\skipDuplicateCheck()) {
$id = record\findOne('MyEntityType', null, null, 'name=', string\concatenate(taxYearRelated, ' - ', monthRelated));
if ($id) {
recordService\throwDuplicateConflict($id);
}
}
// To forbid bypass duplicate checking, you can use this piece of code, which will throw an error when the user click create
if (recordService\skipDuplicateCheck()) {
recordService\throwForbidden("No duplicate check bypass allowed.");
}
And yes (MyEntityType) should be replaced with the name of the entity.
This way you are checking against what makes the name field meaning the composition of the two fields provided by the UI. This should do the job.
Hope this helps
Leave a comment: