Setting properties per record in Forms MRB 20188367001

Setting properties per record in Forms MRB

This is probably described many times before, but you just can’t have enough example code snippets.

Imagine you want to restrict users to update records which end-dates are in the past in a Multi record block. Strangely, there is no way you can set the property for a record at once, so each item’s Update Allowed property must be set seperately. This can be done with the Set_Item_Instance_Property built-in which only affects the current record in the multi record block.

The code in the Post-query trigger might look something like this:

 lv_itemname VARCHAR2( 200);
      IF :block.enddate < sysdate
        lv_itemname := Get_Block_Property( 'BLOCK', First_Item ) ;
        WHILE ( lv_itemname IS NOT NULL )
          lv_itemname := 'block.'||lv_itemname;
          IF Get_Item_Property( lv_itemname, displayed ) = 'TRUE'
          AND Get_Item_Property( lv_itemname, ENABLED ) = 'TRUE'
          AND (  Get_Item_Property( lv_itemname, Item_type ) = 'CHECKBOX'
             OR Get_Item_Property( lv_itemname, Item_type ) = 'TEXT ITEM'
             OR Get_Item_Property( lv_itemname, Item_type ) = 'LIST'
             ( lv_itemname
             , CURRENT_RECORD
             , Update_allowed
             , Property_False
             ) ;
           END IF ;
         END IF ;
         lv_itemname := Get_Item_Property( lv_itemname, NEXTITEM );
       END LOOP ;
     END IF ;

I had to add some code to make sure only displayed items of specific types had their properties altered, thus avoiding errors concerning item types that are not displayed or of inappropriate type (like buttons). The combination of a loop and the Get_item_property( <item>, NEXTITEM ) lets me loop through all items in the block programmatically.

Remember that the  Post-query trigger fires for each record, so the enddate is checked every time a new record is fetched into the block. In the same code the visual attributes (like background color) of individual records can be set.