cancel
Showing results for 
Search instead for 
Did you mean: 

How to bring error message

former_member206299
Contributor
0 Kudos

Hi ,

My requirement is

im giving First name , Last Name and saving the data by clicking on save.

if the first First name and last name is already present in the database then its should not save

but it should show some error message ......but here in this scenario its saving ......and not bringing the error message...

Any suggestions.....

Regards,

Sijo

Accepted Solutions (0)

Answers (6)

Answers (6)

former_member206299
Contributor
0 Kudos

Thanks ...everyone

the issue is solved...

saumya_govil
Active Contributor
0 Kudos

Hi SIjo,

To get the first name and last name entered on UI you can use the following code:

lr_entity ?= me->collection_wrapper->get_current( ).

    IF lr_entity IS BOUND.
      lr_entity->get_property_as_value( exporting iv_attr_name = 'FIRST_NAME'
                                          importing ev_result    = lv_fname ).
      lr_entity->get_property_as_value( exporting iv_attr_name = 'LAST_NAME'
                                          importing ev_result    = lv_lname ).
    endif.

Hope this helps!

Regards,

Saumya

former_member206299
Contributor
0 Kudos

Hi,

I need to read the email .........email attribute is not present in any of the context nodes....

So how can i read the EMAIL id also....

Any suggestions .....

Regards,

Sijo..................

saumya_govil
Active Contributor
0 Kudos

Hi Sijo,

From where do you need to read the value of the email? Is it from the database tables corresponding to the user selected on UI?

If yes, then you can add a select query to the database table based on the first name, last name etc selected on UI and fetch the value of the email ID.

Hope this helps!

Regards,

Saumya

former_member206299
Contributor
0 Kudos

hi saumya ...

I want to read it from the web ui just like the last name and the first name ...

but like the other two its not available in the context nodes.....

lr_entity1 ?= me->ztyped_context->ZEMAIL->collection_wrapper->GET_CURRENT( ).

check lr_entity1 is bound.

lv_test = lr_entity1->get_property_as_string('E_MAIL').

this is the code which ii added to get the email......

but im not able to read the data ...........

any alternatives .....

Regards,

Sijo...

Former Member
0 Kudos

Hi Sijo,

Can u give some more detail like component name, view and context node name, where u want to read this e-mail attribute.

Have u added this context node through wizard??

Regards

Gaurav

saumya_govil
Active Contributor
0 Kudos

Hi Sijo,

If the field Email is not available on the UI then you would not be able to fetch its value.

You need to first add this attribute to the contact node using the BOL entity structure append. The when it becomes visible in the context node, add this field in the configuration on UI.

Then fetch the value in your code.

Reagrds,

Saumya

brishketu_svatsa
Explorer
0 Kudos

Hello Sijo, Gaurav,

First answer first...

every view has the implementation class with the context nodes. The data should be available via the context node which recieves data from the data binding concept of the BSP.

The data in the IMPL class can be recieved via the typedcontext attribute.

Still, this is not the best way of doing the code if we are following the UI Framework. The business validation in the UI should and must happen in the IL which is nothing but the GENIL implementation class of the business. Once, the check fails as Gaurav has mentioned, the error message should get added via the CLCRM_GENIL_MESS_CONT_MANAGER class ...

I hope this helps!

former_member206299
Contributor
0 Kudos

Hi

Any sample code to read the first name and last name attributes.....

Regards,

Sijo..

brishketu_svatsa
Explorer
0 Kudos

You can use something like this on the UI:

lr_entity = me->typed_context->employeeresponsible->collection_wrapper->get_current( ).

CALL METHOD lr_entity->get_property_as_string

EXPORTING

iv_attr_name = 'PARTNER2' "#EC NOTEXT

RECEIVING

rv_result = lv_bp_id.

But, the data can also be retrieved in the CL_CRM_BUIL class where we actually send the BUILHEADER object for actual DB save. I am not too sure if you are already familiar with BOL/GENIL programming language.

You can read more on the service.sap.com/okp.

I hope this helps!

brishketu_svatsa
Explorer
0 Kudos

Hello Sijo, Gaurav,

Kindly refrain from calling database commits or rollbacks from the UI layer. The UI Framework has been designed to work efficiently with the IL layer. I would request you to add the check in the IL implementation rather than your UI layer.

I hope you stick to the better practise.

Former Member
0 Kudos

Dear Brishketu,

EN_ONSAVE methos is also the part of IMPL class and in the same method data base commit or rollback perform.

We can check value before database commit and raze message from there .

R u talking about to use CL_CRM_GENIL_MESS_CONT_MANAGER framework class.

Correct me if i m wrong.

Regards

Gaurav

former_member206299
Contributor
0 Kudos

hi Gaurav...

in the IMPL class theres on_save .. method is that the method which u are talkiing about ...

i tried redefining that method.. but tht method is not getting fired when we click on save.....

any alternatives.....

Regards,

Sijo .....

Former Member
0 Kudos

Hi,

In EN_ONSAVE event handler first read both First name and Last name value and compare with data base value.Before Commit check values and raze error message.

Refer sample code for refrence.

lv_FIRSTNAME = lr_entity->get_property_as_string( 'FIRST NAME' ).

lv_LASTNAME = lr_entity->get_property_as_string( 'LASTNAME' ).

Conpare both values with database.

Now check condition.......

IF lv_FIRSTNAME IS NOT INITIAL AND lv_LASTNAME IS NOT INITIAL.

lr_tx = lr_entity->get_transaction( ).

IF ( ( lr_tx->check_save_needed( ) EQ abap_true ) AND

( lr_tx->check_save_possible( ) EQ abap_true ) ) OR

lv_cucompl->force_save = abap_true.

lv_cucompl->force_save = abap_false.

IF lr_tx->save( ) EQ abap_true.

lr_tx->commit( ).

ELSE.

lr_tx->rollback( ).

ENDIF.

..................................

..................................

..................................

..................................

..................................

..................................

..................................

ELSE.

lr_msg_srv = cl_bsp_wd_message_service=>get_instance( ).

IF lr_msg_srv IS BOUND.

lr_msg_srv->add_message(

iv_msg_type = 'E' "#EC NOTEXT

iv_msg_id = iv_msg_id

iv_msg_number = iv_msg_number

iv_msg_v1 = iv_msg_v

iv_important_info = abap_true ).

ENDIF.

ENDIF.

former_member206299
Contributor
0 Kudos

Hi Gaurav....

Theres no event handler en_onsave in this view....

im reading the first name and last name in the set_s_struct method im checking with the data base here only.....

if sy-subrc = 0.

data:

lr_global_messages type ref to cl_crm_genil_global_mess_cont,

lr_core type ref to cl_crm_bol_core.

lr_core = cl_crm_bol_core=>get_instance( ).

lr_global_messages ?= lr_core->get_global_message_cont( ).

call method lr_global_messages->add_message

exporting

iv_msg_type = 'E'

iv_msg_id = 'ZCRM'

iv_msg_number = '000'

iv_msg_text = 'Trying To Duplicate The Business Partner '

iv_show_only_once = 'X'.

exit.

endif.

This is the codew which i wrote but ....eventhought the sy-subrc = 0 the data is getting saved.....

Regards,

Sijo....

Former Member
0 Kudos

Hi Sijo,

SET_XX method is only for passing value to that particular attribute. When u r saving data into data base it is not checking any value for FIRSTNAME OR LASTNAME as per ur requirement.

If u want to do some manupulation based on thes values u can read these values in GET/GET method but while saving system is checking only std. logic and this FIRSTNAME and LASTNAME checking is ur specific requirement .

If u want to check these values there will be one EH_ONSAVE event in event handler of OVERVIEW page. go into that event handler and read ur name values and mapp with ur databas and there according ur requirement u can populate message.

If u r working in BP_HEAD component then overview page for this component BP_HEAD/BPHEADOverview

Regards

Gaurav

former_member206299
Contributor
0 Kudos

Hi gaurav ...

How can we read the first name and last name ....in the event handler EH_ONSAVE method.....

Regards,

Sijo....

brishketu_svatsa
Explorer
0 Kudos

Hello Sijo,

Are you using CRM UI Framework? If so, are you adding up the message in the Interaction Layer (IL) implementation class? meaning: are you already adding up the error message using the message service of the framework?