cancel
Showing results for 
Search instead for 
Did you mean: 

Make field mandatory through coding

Former Member
0 Kudos

Hi experts,

I would like to know if there is a way to make a field mandatory through coding.

I have a field that should become mandatory based on the content of another field.

Any idea on how i can achieve that ?

Thanks for your help.

Regards.

Aw

Accepted Solutions (1)

Accepted Solutions (1)

ajaya_kumar
Active Participant
0 Kudos

Hi,

You could implement the DO_HANDLE_EVENT to check if you have value in the first field and based on that make second field as mandatory.


**********************************************************
data: lv_wrapper type ref to cl_bsp_wd_collection_wrapper,
lv_order type ref to cl_crm_bol_entity,
lv_value1 type string,
lv_value2 type string,
lv_msgsrv type ref to cl_bsp_wd_message_service.

lv_wrapper = typed_context->[contex_node]->get_collection_wrapper( ).
lv_order ?= lv_wrapper->get_current( ).

* Check for required values
check lv_order is bound.

lv_value1 = lv_bp->get_property_as_string( iv_attr_name = '[first_field]' ).

if lv_value1 is not initial.

lv_value2 = lv_bp->get_property_as_string( iv_attr_name = '[second_field]' ).

if lv_value2 is not initial.

lv_msgsrv = cl_bsp_wd_message_service=>get_instance( ).
lv_msgsrv->add_message( iv_msg_type = 'E'
iv_msg_id = '[you_message_class]'
iv_msg_number = 'your_msg_no'
iv_msg_level = '1' ).
endif.
**********************************************************

Hope this helps!

Cheers

Ajay

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

On save event of the object , u cn check for the value of the field.If it is initial u cn throw an error msg or give a popup error and exit the method without saving the object in the database.

With this logic u'll not be able to save the record in the database if the filed value is initial , thereby makin it mandatory for the user.

You can also mark the field as mandatory in the config of the view by setting the field property as checked .

Rgds,

Swati.