Forum Stats

  • 3,839,830 Users
  • 2,262,539 Discussions
  • 7,901,065 Comments

Discussions

master/detail: validation

720605
720605 Member Posts: 6
edited Sep 3, 2009 3:42PM in Forms
Hello all,

let's say I have a master-detail form, displaying recipes as master, and ingredients as detail. Let's say I'm only allowed to mark a recipe as "Low-Calories" if it doesn't contain ingredients A, B, or C.

What trigger would you use? and how do you browse the uncommitted ingredients list programatically to check for presence of A, B, or C?

EXAMPLE

Recipe ____________________ Type
=====================================
John's Breakfast ____________ Standard
Jim's Lunch ________________ Low-Calories
=====================================

(Sorry don't know how to use a monospaced font)

The user edits John's breakfast and marks it standard, and then goes to the ingredients list, and deletes any records for A, B, and C; and later goes back to the recipe master record and wants to replace the "Standard" value with "Low-Calories" value. This should be allowed only after ensuring that no A, B, or C are found in the detail records.

Thanks for your help and tips!

Edited by: user2339825 on Sep 2, 2009 2:24 PM

Best Answer

  • Magoo
    Magoo Member Posts: 1,495
    Answer ✓
    Hi!
    you mean from first-record to last-record ...
    declare
    l_cur_rec pls_integer := :system.cursor_record;
    begin
    first_record;
    loop
      if
        your_condition_check
      then
        your_action;
      end if;
      if
        :system.last_record = 'TRUE'
      then
        exit:
      end if;
      next_record;
    end loop;
    go_record ( l_cur_rec );
    end;
    btw: monospace with {noformat}
     text 
    {noformat}

Answers

  • Kuba Flejmer
    Kuba Flejmer Member Posts: 66
    Hi,

    You can solve this in two ways:
    Let's say that type is on the list item. In the trigger when-list-changed you can check this:
    1. Go to the details block. Go through all the records and check ingredients.
    2. Make query and check ingredients (but it needs to use "post" after each operation on details block).

    Regards
    Jakub
    Kuba Flejmer
  • 720605
    720605 Member Posts: 6
    1. Go to the details block. Go through all the records and check ingredients.
    Yes, that's what I need to do. Any hints on syntax? how do I go from first...last item in the detail block?

    Thanks in advance!
  • Andreas Weiden
    Andreas Weiden Member Posts: 10,871 Gold Crown
    If your "low calories" marker-item is a checkbox or a poplist, you can use either the WHEN-CHECKBOX-CHECKED-trigger or the WHEN-LIST-CHANGED-trigger and do something like:
    DECLARE
      bABCFound BOOLEAN:=FALSE;
    BEGIN
      GO_BLOCK('DETAIL');
      FIRST_RECORD;
      LOOP
        EXIT WHEN :SYSTEM.RECORD_STATUS='NEW';
        IF :DETAIL.TYPE IN ('A','B', 'C') THEN
          bABCFound:=TRUE;
          EXIT;
        END IF;
        EXIT WHEN :SySTEM.LAST_RECORD='TRUE';
        NEXT_RECORD;
      END LOOP;
      IF bABCFound THEN
        -- Do whatever you want here
      END IF;
    END;
    Andreas Weiden
  • Magoo
    Magoo Member Posts: 1,495
    Answer ✓
    Hi!
    you mean from first-record to last-record ...
    declare
    l_cur_rec pls_integer := :system.cursor_record;
    begin
    first_record;
    loop
      if
        your_condition_check
      then
        your_action;
      end if;
      if
        :system.last_record = 'TRUE'
      then
        exit:
      end if;
      next_record;
    end loop;
    go_record ( l_cur_rec );
    end;
    btw: monospace with {noformat}
     text 
    {noformat}
  • 720605
    720605 Member Posts: 6
    thanks guys. i wanted to mark both answers as correct but it wouldn't let me.

    cheers
  • Magoo
    Magoo Member Posts: 1,495
    Thanks!
    Andreas was more detailed, so he is more correct, i think ...
    But anyway, he has enough ... :)
    Regards
This discussion has been closed.