How can i get value from specific item instance?

CrazyDiamond picture CrazyDiamond · May 18, 2011 · Viewed 7k times · Source

I'm trying to create multi-item database based form. When i open it, it will be populated by one record only, always. And i want functionality in it, that will fill all fields of new created record, same as they are in the first (selected from DB) record. Just copy them from the first record, that's it.

I'm trying to use WHEN-NEW-ITEM-INSTANCE trigger and ":system.record_status IN ('NEW','INSERT')" condition, but i don't know, how to tell Forms, that i need value from my first record. I mean,

IF :system.record_status IN ('NEW','INSERT')
THEN
  :block.item := <<here goes pointer to my first record of that item>>
END IF;

So, how can i get value from specific item instance?

Thanks in advance.

Answer

APC picture APC · May 18, 2011

Create a dummy block, one that is invisible to the users. Populate it with your default record as part of the WHEN-NEW-FORM-INSTANCE trigger.

Then in your actual DATA block you can reference the items in the dummy block to pre-populate the items. I would probably choose to use a higher level trigger such WHEN-CREATE-RECORD rather than having a swarm of WHEN-NEW-ITEM-INSTANCE triggers, but it depends on how the rest of your design hangs together.


"Thats a crude solution"

Sorry, I hadn't realised that you were displaying the default record to the users. However, as far as I know Forms does not have any mechanism to reference a record other than the current record (full disclosure: I haven't actually used Forms for a while and I don't have access to test whether this is still the case).

What you could do is:

First_Record;
Duplicate_Record;

This also has a downside, as the user may find the navigation jump confusing.