cancel
Showing results for 
Search instead for 
Did you mean: 

Delete ContactRel entities of Account and modify Account collection at runtime

former_member207526
Participant
0 Kudos

HI Experts ,

I have requirement to Search Account information and its related Contact relation on based of Email ID .I want to delete entities from Contact relation for particular criteria and modify the Account Entity .

1. I have search account at IC agent for Email ID

     CALL METHOD fire_query
           EXPORTING
             it_parameters       = lt_parameters  ----->  "Email = rishi.verma@gmail.cm"
             iv_query_service    = query_service
           IMPORTING
             er_bo_col           = bo_col -------------------> In this Collection -> Am getting One Account and Its 4 Relation Fig 1.1
             ev_no_exact_matches = lv_no_exact_matches
           CHANGING
             cv_query_type       = lv_query.


FIG 1.1                                                                                                                        

  

There is 13 Entities for BuilContactPersonRel  Fig 1.2

Fig 1.2

 

So my issue is i have to delete top 10 entities (BuilContactPersonRel) )where Contact Email is not Equal to Account Email ,  And i want to Update bo_col  with 3 remain entities as am passing this to Context node . I am looking for BOL logic to achieve this ...


I just want to remove entity from bo_col not permanent from database .


bo_col and ir_bo_col same....




Regards,

Rishi verma

Accepted Solutions (1)

Accepted Solutions (1)

dharmakasi
Active Contributor
0 Kudos

Hi Rishi,

There are many ways to achieve this requirement. but i do not understand why do you want to changes only buffer, if you want to changes buffer you can directly access the required data where ever you want to use it.

However you can use filter by property method from the iterator class. Create a instance for the iterator class using

lr_iterator ?=  ir_bo_col->get_iterator(  ).

lr_iterator->filter_by_property( iv_attr_name = 'field name to filter' iv_value = 'email id' ).

Best Regards,

Dhharmakasi.

former_member207526
Participant
0 Kudos

Thanks for replying...

I want to explain more ..

1. i want to search account on based of email id and when search done i am getting 13 entities for contact for that account .

Account email id : dilling3@bellsouth.net

and there are 2 contact as shown below having same email id ..

So i want to display only two of them contact having same email id as account having.

  

2. ir_bo_col contain  account entity and in it relation have contact with its 13 entity , so i want to remove 11 entity from contact relation  and want to show only 2 in contact view ....

I hope it clear to know more...

I guess applying filter on ir_bo_col not work becuase it will add filter to Account entity not it relation (Contact) .

Do have any idea ?

Regards,

Rishi

former_member207526
Participant
0 Kudos

I have solved it my self . Actually when Contact View collection is getting filled then i added filter of email id .Now is working fine ..

Thanks a lot for your solution ...

Regards,

Rishi

Answers (1)

Answers (1)

former_member193634
Active Participant
0 Kudos

Hello,

This is totally doable.

You can create your own collection and set it to the given context node.

Something like that :


*__ Creation of new collection

CREATE OBJECT lr_newcol
TYPE
cl_crm_bol_bo_col.

TRY.
lr_it = iv_col->get_iterator( ).
IF lr_it IS BOUND.
lr_entity ?= lr_it->get_first( ).

WHILE lr_entity IS BOUND.
*__ Here do some custom test for filtering
IF "criteria is OK to add entity to collection".
*__ Add entity to collection
lr_newcol->add( lr_entity ).
ENDIF.
lr_entity ?= lr_it->get_next( ).
ENDWHILE.
ENDIF.

CATCH cx_crm_genil_model_error.
CATCH cx_sy_ref_is_initial.
ENDTRY.

*__ Now set collection to context node

me->typed_context->customers->set_collection( lr_newcol ).


Hope this helps,

Best regards,

Sylvain AGUETTAZ