cancel
Showing results for 
Search instead for 
Did you mean: 

set_property is not working

Former Member
0 Kudos

Hi,

I am trying to over write the values of the attributes in my entity. But the set_property is not working. Following is the piece of my code.Can anyone suggest how to achieve this.I have written this code in my event while closing a pop up window.

It does not change the values in lr_entity.Please help.

lr_current1 ?= me->typed_context->relationship->collection_wrapper->get_current( ).

lr_entity1 ?= lr_current1.

TRY.

lr_entity ?= lr_entity1->get_related_entity( iv_relation_name = 'BuilContactPersonStandardAddressRel' ).

CATCH cx_root .

ENDTRY.

IF lr_entity IS BOUND.

  • lr_entity->switch_to_change_mode( ).

me->view_group_context->set_view_editable( me ).

lr_entity->set_property_as_string(

iv_attr_name = 'BP_NUMBER' "#EC NOTEXT

iv_value = lv_account ).

lv_contact = lv_contp.

lr_entity->set_property_as_string(

iv_attr_name = 'CONP_NUMBER' "#EC NOTEXT

iv_value = lv_contact ).

lr_entity->set_property_as_string(

iv_attr_name = 'ADDRESS_GUID' "#EC NOTEXT

iv_value = lv_guid )."gv_string )

lr_entity->set_property_as_string(

iv_attr_name = 'ADDR_SHORT' "#EC NOTEXT

iv_value = gv_string ).

ELSE.

TRY .

lr_entity = lr_entity1->create_related_entity( iv_relation_name = 'BuilContactPersonStandardAddressRel' ).

CATCH cx_root.

ENDTRY.

IF lr_entity IS BOUND.

lr_entity->set_property(

iv_attr_name = 'ADDRESS_GUID' "#EC NOTEXT

iv_value = gv_addressguid ).

lr_entity->set_property(

iv_attr_name = 'ADDR_SHORT' "#EC NOTEXT

iv_value = gv_string )

lr_entity->set_property(

iv_attr_name = 'BP_NUMBER' "#EC NOTEXT

iv_value = gv_account ).

lr_entity->set_property(

iv_attr_name = 'CONP_NUMBER' "#EC NOTEXT

iv_value = lv_contp ).

ENDIF.

ENDIF.

Accepted Solutions (1)

Accepted Solutions (1)

former_member202474
Contributor
0 Kudos

Hi ginger,

Try using Set_properties method and see. By the way to set the attribute you need not write the code to chaneg it to a change mode, instead diretly you can set it.

Regards,

Ruby.

Former Member
0 Kudos

Hi Ruby,

I have already used set_properties, but no use. Also I used the change mode, as I felt because the view may goes to non editable mode once the data(this is address data in contact create screen) get selected.

Please help with any other solution.

Thanks.

kavindra_joshi
Active Contributor
0 Kudos

DId you do a save or commit after the change ? If not then the values will not be seen to you.

The transactional behavior in CRM implies that you have to call a save / commit. Its the same as modifying an entity in the genil_bol_browser and not saving. So next time you would not see the changes made because you have not persisted the changes.

Regards

Kavindra

Edited by: joshi_kavindra on Nov 30, 2011 7:28 PM

Former Member
0 Kudos

Hi Kavindra,

Please let me know how to commit in bol programming as I am new to this concept.

Thanks.

kavindra_joshi
Active Contributor
0 Kudos

Check this code snippet


data: core type ref to cl_crm_bol_core.
core = cl_crm_bol_core=>get_instance( ).
core->start_up( 'CRMIC_DEFAULT' ).

end-of-selection.
  data: qs type ref to cl_crm_bol_query_service,
        result type ref to if_bol_bo_col,
        ent type ref to cl_crm_bol_entity.

  qs = cl_crm_bol_query_service=>get_instance( 'BTQuery1O' ).
  qs->set_property( iv_attr_name = 'OBJECT_ID'
                    iv_value = '0005000000' ).

  result ?= qs->get_query_result( ).
  ent ?= result->get_first( ).
  ent = ent->get_related_entity( 'BTOrderHeader' ).

  check ent->lock( ) = abap_true.

  data: descr type crmt_process_description.

  ent->get_property_as_value( exporting iv_attr_name = 'DESCRIPTION'
                              importing ev_result = descr ).

  concatenate descr 'changed' into descr separated by space.

  ent->set_property( iv_attr_name = 'DESCRIPTION'
                     iv_value     = descr ).

  core->modify( ).

  data: tx type ref to if_bol_transaction_context.

  tx = ent->get_transaction( ).
  if tx->save( ) = abap_true.
    tx->commit( ).
  else.
    tx->rollback( ).
  endif.

  data: str type string.
  str = ent->get_property_as_string( 'CHANGED_AT' ).

kavindra_joshi
Active Contributor
0 Kudos

Also check the properties i.e. is the fielld read only or editable before you perform the set property.

Regards

Kavindra

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Please check if your entity is locked and is editable. Also please check if your attributes are readonly.

If both answers are yes then, please get instance of cl_crm_bol_core and then modify after you change your attributes.

DATA lr_core TYPE REF TO cl_crm_bol_core.

lr_core = cl_crm_bol_core=>get_instance( ).

lr_core->modify( ).

Regards,

BJ