Pregunta

I have a form with two datablocks (besides for control), A and B. A only supports a single record, B supports multiple records. When inserting A, I want to ensure at least one record is going to be inserted on B.

What I would like to do is to put in the pre-insert trigger of A

go_block('B')
if record_count = 0 then
    message('Please enter in at least one b');
else
    --Other validation stuff
end if;

But, to my knowledge, no record_count like function exists. So how would I duplicate such functionality?

P.S. I've tried...

go_block('B')
first_record
if :system.last_record = 'TRUE' then
    message('Please enter in at least one b');
else
    --Other validation stuff
end if;

And that doesn't work either.

Edit:

Per nightfox's suggestion, I did the following in the key commit section of the form.

commit_form;

was replaced with:

if :B.Value_That_Is_Required is null then
    message('Please enter in at least one b');
else
    commit_form;
end if;

I also needed to change what happened on key-exit as that checked to see if changes should be saved as well, but it basically followed the same format.

¿Fue útil?

Solución

You should overwrite the key-commit trigger. In this trigger you can first go to block "B" and the check the record is entered valid. For example if B contains a persons name, firstname and birthdate and the name is required, you just check if the name is not null. If this ain't the case the record is empty and no records are entered, if the name is not null then the record is entered and you have at least one record in block B if you have written some validation triggers on the items or a validate_record trigger then you are already sure the record is valid. At this moment you can do a commit_form in the key-commit trigger, otherwise you can give a message.

The only thing you might also need to check is if nobody can delete the record in block B without deleting the record in block A, because then you also have no records in block A.

Kind regards

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top