cancel
Showing results for 
Search instead for 
Did you mean: 

Cannot read attribute of another context node in a context node

Former Member
0 Kudos

Hello Sap gurus,

such a long time that I do not post any issue. Now unfortunately time has come down.

My functional requirement is that whenever the status of an opportunity is changed from "Won" to "Booked", then I have to retrieve the Status reason previously marked for the status "Won" and paste into the attribute Status_Reason (CON_KEY) for status "Won".

In order to do that I need to read the context node BTADMINH or ZBTCUSTOMERH from the context node BTSUBJECT, in the method GET of attribute CON_KEY.

I have implemented the following code in the method GET_CONC_KEY of the context node BTSUBJECT.

  DATA:
          lr_entity TYPE REF TO cl_crm_bol_entity,
        lr_comp TYPE REF TO ZL_BT111H_O_DETAILS_IMPL,
         lv_ref_guid     TYPE        crmt_object_guid,
         lr_collection TYPE REF TO cl_crm_bol_bo_col,
         lr_bdc type ref to  if_crm_ui_data_context.

    TRY.
lr_entity ?= lr_comp->ZTYPED_CONTEXT->ZBTCUSTOMERH->collection_wrapper->get_current( ).
     lv_ref_guid = lr_entity->get_property_as_string( iv_attr_name = 'REF_GUID' ).
      CATCH cx_sy_ref_is_initial.

      ENDTRY.

Whenever I try to read the context node BTADMINH or ZBTCUSTOMERH from BTSUBJECT  I got always the same dump:

OBJECTS_OBJREF_NOT_ASSIGNED ZL_BT111H_O_DETAILS_CN06======CP CRM

Somethins is defitenely wrong and I am at the moment stuck with this code.

Please any help is really welcome.

Thanks in advance,

Andrea

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

So if I understood properly you have two context nodes C1 and C2 and the corresponding context node classes are CL1 and CL2 respectively. Now you need to read an attribute of C2 from class CL1.

You can do it by the following steps.

1. Define an attribute A2 in CL1 TYPE REF TO CL2.

2. In the DO_INIT_CONTEXT method of the view implementation set the attribute with the instance of the context node C2 by the following code

A2 ?= me->typed_context->C2->collection_wrapper->get_current( ).

3. Now you can access the attribute A2 in your class CL1.

Hope this helps.

Regards,

Sayan

Former Member
0 Kudos

Hi Sayan,

many thanks for the answer. I saw as well your blogs. Indeed I have to retrieve the value from a specific attribute of context node BTCUSTOMERH or BTAdminH, but within the context node BTSUBJECT.

I have tried what you said but eventually I have to write code in the method GET of my attribute A1, (coming back to your example). In order to do that I have to invoke the component controller.

But unfortunately I am not able to initialize the component controller in order to retrieve my context node. So I got the above DUMP.

Anyway I thank you for the idea.

Regards.

Andrea

Answers (1)

Answers (1)

former_member197655
Active Participant
0 Kudos

Hi Andrea ,

Please try this code .

   TRY.
lr_entity ?= lr_comp->ZTYPED_CONTEXT->ZBTCUSTOMERH->collection_wrapper->get_current( ).


IF lr_entity IS BOUND.
     lv_ref_guid = lr_entity->get_property_as_string( iv_attr_name = 'REF_GUID' ).
      CATCH cx_sy_ref_is_initial.

ENDIF.

ENDTRY.



Hope it helps.




Regards,

Manjeet Singh.

Former Member
0 Kudos

Hi Manjeet,

many thanks for your prompt answer.

Unfortunately the code you suggested is not helping, since I am still having problem in the first part of the code.

lr_entity ?= lr_comp->ZTYPED_CONTEXT->ZBTCUSTOMERH->collection_wrapper->get_current( ).

As said, I got straight the dump:

OBJECTS_OBJREF_NOT_ASSIGNED ZL_BT111H_O_DETAILS_CN06======CP CRM

Best Regards,

Andrea

former_member197655
Active Participant
0 Kudos

Hi Andrea,

Sorry I got it wrong , for lr_comp you will have to take reference from controller IMPL class.

DATA:
          lr_entity TYPE REF TO cl_crm_bol_entity,
        lr_comp TYPE REF TO ( component controller IMPL class),
         lv_ref_guid     TYPE        crmt_object_guid,
         lr_collection TYPE REF TO cl_crm_bol_bo_col,
         lr_bdc type ref to  if_crm_ui_data_context,

         comp_controller type cl_bsp_wd_component_controller.



lr_comp  ?= me->comp_controller.


IF lr_comp IS BOUND.

    TRY.
lr_entity ?= lr_comp->ZTYPED_CONTEXT->ZBTCUSTOMERH->collection_wrapper->get_current( ).
     lv_ref_guid = lr_entity->get_property_as_string( iv_attr_name = 'REF_GUID' ).
      CATCH cx_sy_ref_is_initial.

      ENDTRY.


ENDIF.



Hope it helps.



Regards,

Manjeet Singh.



Former Member
0 Kudos

Hi Manjeet,

I have tried what you said, but indeed it does not work, as you have to declare lr_comp as attribute of the context implementation class.

Eventually I got the same dump. Anyway I feel like rewarding you for the ideas.

Perhaps I got confused from this blog as here it's too late.

Best Regards.

Andrea