cancel
Showing results for 
Search instead for 
Did you mean: 

How to get value in Second Drop Down based on selection made in first dropd

Former Member
0 Kudos

Hi All,

I have a table with first two columns as dropdown.

The values in first drop down are fixed. However the value in second dropdown should be populated based on selection made in first .

e.g

First Column had different departments say IT, SALES, HR.

Based on department selected I have to populate employee of that department.

For first dropdown I have taken Drop down by index.

What should I select for second drop down and achieve desired functionality? Please guide.

Regards,

Madhvika

Accepted Solutions (1)

Accepted Solutions (1)

Abhinav_Sharma
Contributor
0 Kudos

Hi Madhavika,

What you can do is create one action and set this action onSelect Event of firstdrop down. Now, whenever user selects the value from first dropdown, this action will be called. Inside this action you can write your business logic to get the values for your second drop down box.

Now you can populate the second drop down box based upon the values. Suppose you are getting values in internal table of type secondNode (This is the node which you will bind to second drop down).

Now you can write a logic in action:

  • create local data variable to access context information

Data: lo_node type ref to if_wd_context_node.

  • create table based on context structure

Data: it_node type STANDARD TABLE OF if_view1=>element_SECONDNODE,

wa_node like line of it_node.

<get values in internal table as per your logic >

lo_node = wd_context->get_child_node( name = 'SECONDNODE' ).

lo_node->BIND_TABLE( it_node ).

For more info on drop down you can refer [Dropdown Tutorial|http://www.sapdev.co.uk/sap-webapps/sap-webdynpro/wdp-dropdown.htm]

Regards

Abhinav

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi

Use drop down by key for fixed values IT, SALES, HR. create on_select action for that drop down.

in on_select method code like this..

DATA lo_nd_segment1 TYPE REF TO if_wd_context_node.

DATA lo_el_segment1 TYPE REF TO if_wd_context_element.

DATA ls_segment1 TYPE wd_this->Element_segment1.

data lt_segment1 type wd_this->elements_segment1.

DATA lv_segment TYPE wd_this->Element_segment1-segment.

data lr_column type ref to cl_wd_table_column.

  • navigate from <CONTEXT> to <SEGMENT1> via lead selection

lo_nd_segment1 = wd_context->get_child_node( name = wd_this->wdctx_segment1 ).

  • get element via lead selection

lo_el_segment1 = lo_nd_segment1->get_element( ).

lo_el_segment1 = WDEVENT->GET_CONTEXT_ELEMENT( 'CONTEXT_ELEMENT' ).

  • get all declared attributes

lo_el_segment1->get_static_attributes(

IMPORTING

static_attributes = ls_segment1 ).

now ls_segment1 contains your first drop down selection value.

DATA : lv_dropdown type string .

lv_dropdown = ls_segment1-segment.

if lv_dropdown = 'IT'.

// here fill your second drop down based on IT value.

endif.

Hope it solves.

Cheers,

Kris.

Former Member
0 Kudos

Hi Abhinav ,

Thanks for your quick reply . This is what i was looking for.

I will work on it and update the post most importantly awarding points .

Hi kissnas ,

Thanks for your reply . However whatever you have said , I had already done it . What I was excatly looking for populating the secodn node .

Regards,

Madhivka

Former Member
0 Kudos

Hi Abhinav,Hi Kissas

I am able to populate the values in second dropdown based on selection in first dropdown the way you suggested.

However when I perform some action on elements and bind the elements to table again. The dropdown value vanishes or if I save my table data and come back to screen again. There is no dropdown values for second dropdown reason being the to populate the second dropdown is written in on select method of first dropdown and not in supply function .

when we pass values to dropdown via supply function it will remain. As in this case there is no supply function I am not getting dropdown values.

Can you please help how I can retain the dropdown values for second drop down?

Regards,

Madhvika

Abhinav_Sharma
Contributor
0 Kudos

Hi Madhavika,

What you can do is, you can call the same method in inbound plug that you are calling onSelect of first dropdown. This will repopulate the second dropdown based on the values which is selected in the firstdrop down.

In case, your first value also got vanishes then, you can retain that value in component controller and then read it back to populate the second drop down.

Regards

Abhinav Sharma

Former Member
0 Kudos

Thanks Abhi nav for your prompt response .

calling the method again wont wrk as there is other code also in it that will not work on starting .

Only option left is to read the values again from backend . This will result in all 3 calls to backedn for same code. I was thinking that .

Any other idea?

Awarded points to you .

Abhinav_Sharma
Contributor
0 Kudos

HI Madhvika

I dont have any other idea, probably you can try reading values from back-end as you suggested.

Regards

Abhinav