Monday, March 26, 2012

How to Dynamically Populate a Pop List ?

People want to know, how they dynamically populate a pop list? Means, At run time pop list will be populate. So there is no hard coded list element. Don't want to wait ?

You are at right place to learn it.

For this example code, i used SCOTT schema and DEPT table. You have to select privilege on the table.

It's a simplest example, First create a non-database block named DUMMY. create an item with type List Item named TXT_LIST. Data type CHAR, Length 30.
Now create a When-New-Form-Instance trigger at form/block level and write down the following code,

DECLARE
    group_id RecordGroup;
    group_name varchar2(10) :='abc';
    status NUMBER;
BEGIN
    group_id := find_group(group_name);
    if not id_null(group_id) then
        delete_group(group_id);
    end if;
   
    group_id := Create_Group_From_Query(group_name,'select DNAME,TO_CHAR(DEPTNO) from DEPT');
/* Select statement must have two column*/
    status := Populate_Group(group_id);
    Populate_List('DUMMY.TXT_LIST',group_id);
END;


Hope it works...

4 comments:

  1. Salam, Hamid i have tried this code in 6i and 10g both, it works in 6i but not in 10g....what can be the possible reason ?? I am unable to populate list item from table.... checked different websites for solution but no use in 10g....

    Regards
    Masood

    ReplyDelete
  2. Finally solved... it was a matter of TO_CHAR only... database column was number type just converted in character in query and solved.... but thanks for your solutions in blog.... :)

    Regards
    Masood

    ReplyDelete
    Replies
    1. Thanks, same problem here but finally solve

      Delete
  3. Hello,
    I wonder what you mean with "group_name varchar2 (10): = 'abc';" because I get an error: FRM - 41072 can not create it "abc" group, please help me.

    thanks

    ReplyDelete