Setting properties per record in Forms MRB

0

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:

DECLARE
 lv_itemname VARCHAR2( 200);
BEGIN
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IF :block.enddate &lt; sysdate<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; THEN<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lv_itemname := Get_Block_Property( 'BLOCK', First_Item ) ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WHILE ( lv_itemname IS NOT NULL )<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOOP<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lv_itemname := 'block.'||lv_itemname;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  IF Get_Item_Property( lv_itemname, displayed ) = 'TRUE'<br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND Get_Item_Property( lv_itemname, ENABLED ) = 'TRUE'<br />&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AND (&nbsp; Get_Item_Property( lv_itemname, Item_type ) = 'CHECKBOX'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OR Get_Item_Property( lv_itemname, Item_type ) = 'TEXT ITEM'<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OR Get_Item_Property( lv_itemname, Item_type ) = 'LIST'<br />&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br />&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; THEN<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set_Item_Instance_Property<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( lv_itemname<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , CURRENT_RECORD<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , Update_allowed<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , Property_False<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp; END IF ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; END IF ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lv_itemname := Get_Item_Property( lv_itemname, NEXTITEM );<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END LOOP ;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --<br /> &nbsp;&nbsp;&nbsp; END IF ;
END;<br />

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.

 

Share.

About Author

Comments are closed.