cancel
Showing results for 
Search instead for 
Did you mean: 

BADI_CRM_BP_UIU_DEFAULTS with method GET_DEFAULT_VALUES

Former Member
0 Kudos

Hi,

I am trying to use the BADI_CRM_BP_UIU_DEFAULTS to default the Country field on an account. I found sample code to update fields within the view AccountDetails.htm of the BP_HEAD component which is read when the screen first loads, but the country field is actually in StandardAddress.htm of BP_ADDR. How would I go about accessing the country field?

Thanks,

Bernard

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Bernard,

You can do the following way.

I hope you want to access the country in the BP_HEAD component. In the view BP_HEAD/AccountDetails, there is a context node called HEADER.

Data : lr_entity type ref to CL_CRM_BOL_ENTITY,
          lv_country type string.

lr_entity ?= HEADER->get_related_entity ( 'BuilStandardAddressRel').

lv_country = lr_entity->GET_PROPERTY_TEXT('COUNTRY').

Let me know if this wat you looking for

Regards,

Vinay

Former Member
0 Kudos

Hi Vinay,

Is it possible to access the COUNTRY field itself and not the text?

Former Member
0 Kudos

Does it mean that you want get the Country Code like (UK for Britan) ?? The code mentioend above will return you the value..

The method GET_PROPERTY_TEXT just converts the values of the attributes into string and returns a string value.. Thats it..

What ever attribute name you pass to the method, that value will be returned as a text..

Vinay

Former Member
0 Kudos

Vinay,

I want to be able to default the country code to "US" each time a person creates an account.

Thanks,

Bernard

Former Member
0 Kudos

Hi

The code is as follows:

ASSIGN lr_typed_context->('STANDARDADDRESS') TO <context_node>.
        IF sy-subrc = 0.
          TRY.
              lr_node            ?= <context_node>.
            CATCH cx_sy_move_cast_error.  "EC_NOHANDLER
          ENDTRY.
          IF lr_node IS BOUND.
            lr_coll_wrapper ?= lr_node->collection_wrapper.
            IF lr_coll_wrapper IS BOUND.
              TRY.

                                    lr_current ?= lr_coll_wrapper->get_current( ).
                  CHECK lr_current IS BOUND.

                  
                  lr_current->set_property( iv_attr_name = 'COUNTRY'
                             iv_value = 'US' ).


               CATCH cx_sy_move_cast_error.
                  lv_xcreation = abap_true.
              ENDTRY.
            endif.
          endif.
        ENDIF.

Regards,

Sowmiya

Former Member
0 Kudos

Thanks Sowmiya,

Did this work for you? I'm getting a sy-subrc error on the first line of your code.

Thanks,

Bernard

Edited by: Bernard Greene on Jan 12, 2009 4:24 PM

Former Member
0 Kudos

Hi

This is code that works. You will get a sy-subrc error until that context node is called. You will go to a break point you set here at least 4 times in the 'Create Account' screen. I dont know the exact technical terminology but when the class for the Standard address context node is instantiated, sy-subrc is 0 and the code runs through. Please place a break-point in the code and check it out.

Regards,

Sowmiya

Former Member
0 Kudos

Hi,

I did notice that it runs about 4 times, but in my case, the value never changed to 0. Just to make sure I have it the same way you do, you have this in IF_UIU_BP_DEFAULTS~GET_DEFAULT_VALUES, right?

Former Member
0 Kudos

Hi

It is the same implementation. You do have a Standard Address area on your screen dont you? I cannot understand. This should execute already in the first class instantiation.

Regards,

Sowmiya

Former Member
0 Kudos

Yes, I do have the Standard Address area. I changed the code and this is what works for me, any idea why?

ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.
  IF sy-subrc = 0.
    lr_typed_context ?= <typed_context>.
    IF lr_typed_context IS BOUND.
      ASSIGN lr_typed_context->('STANDARDADDRESS') TO <context_node>.
      IF sy-subrc = 0.
        TRY.
            lr_node            ?= <context_node>.
          CATCH cx_sy_move_cast_error.  "EC_NOHANDLER
        ENDTRY.
        IF lr_node IS BOUND.
          lr_coll_wrapper ?= lr_node->collection_wrapper.
          IF lr_coll_wrapper IS BOUND.
            TRY.
                lr_current ?= lr_coll_wrapper->get_current( ).
                CHECK lr_current IS BOUND.
                lr_current->set_property( iv_attr_name = 'COUNTRY'
                           iv_value = 'US' ).
              CATCH cx_sy_move_cast_error.

            ENDTRY.

          ENDIF.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.

Former Member
0 Kudos

Hi

I am sorry I forgot to include the first part of the code. Good it works for you.

Regards,

Sowmiya

Former Member
0 Kudos

I awarded you points for your help

Former Member
0 Kudos

Thanks...

Former Member
0 Kudos

Hi Experts,

I am trying to set default values for some of the attributes in my enhanced component IUICMD.

I have enhanced 4 views SearchAccount, DetailAccount, CretaePerson & CreateOrg.

I wish to the BADI, which was highlighted here can be used for my requirement. Or i wish to know how to find

out if any BADI exists for my component IUICMD.

Thanks in advance...

Regards,

Prabahar

Former Member
0 Kudos

Hey Guys,

I tried the exact same thing with the code supplied and it worked perfectly. So I tried to set some default values for another view (BP_SALES/CorpAccountShippingEF) but with no result. Since the BADI is called in the do_prepare_output method of this view as well I simply added a view more lines according to the changed context nodes:



ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.
  IF sy-subrc = 0.
    lr_typed_context ?= <typed_context>.
    IF lr_typed_context IS BOUND.

      ASSIGN lr_typed_context->('STANDARDADDRESS') TO <context_node>.
      IF sy-subrc = 0.
        TRY.
            lr_node            ?= <context_node>.
          CATCH cx_sy_move_cast_error.  "EC_NOHANDLER
        ENDTRY.
        IF lr_node IS BOUND.
          lr_coll_wrapper ?= lr_node->collection_wrapper.
          IF lr_coll_wrapper IS BOUND.
            TRY.
                lr_current ?= lr_coll_wrapper->get_current( ).
                CHECK lr_current IS BOUND.
                lr_current->set_property( iv_attr_name = 'LANGU'
                       iv_value = 'DE' ).
              CATCH cx_sy_move_cast_error.
            ENDTRY.
          ENDIF.
        ENDIF.
      ENDIF.

      ASSIGN lr_typed_context->('BUILSHIPPINGTERMS') TO <context_node>.
      IF sy-subrc = 0.
        TRY.
            lr_node            ?= <context_node>.
          CATCH cx_sy_move_cast_error.  "EC_NOHANDLER
        ENDTRY.
        IF lr_node IS BOUND.
          lr_coll_wrapper ?= lr_node->collection_wrapper.
          IF lr_coll_wrapper IS BOUND.
            TRY.
                lr_current ?= lr_coll_wrapper->get_current( ).
                CHECK lr_current IS BOUND.
              lr_current->set_property( iv_attr_name = 'SHIPPING_COND'
                           iv_value = '00' ).
              CATCH cx_sy_move_cast_error.
            ENDTRY.
          ENDIF.
        ENDIF.
      ENDIF.

     ENDIF.
  ENDIF.

endmethod.

It seems that lr_current isn't bound at the time the BADI sets the default for the Shipping Conditions (SHIPPING_COND) while setting of LANGU works just fine.

Am I missing something here? What am I doing wrong???

Former Member
0 Kudos

I,m facing same problem defoult values "IN" & Language "EN" in the UI when user is creating the BP.

these values shud pick in the Lang and country feilds.

pls can guide me in this regards, pls mail to c.ramsapcrm-gmail-com

Former Member
0 Kudos

Bernard, It's nice to see some working code.

I am defaulting the Grouping field using this same BADI and method. The idea being that if either the Account, Contact or Employee screen is displayed the Grouping code will be defaulted to either 'CRM Account', 'CRM Contact' etc...

My problem is that within the code how I can detect which of the screens was being edited (Account/contact/employee) so that I can then set the Grouping field, if blank.

I also need to set the Role as well, so a Contact may have a Role of 'Prospect', for example.

I wondered if anyone had achieved anything similar to this?.

Jason

Former Member
0 Kudos

See above questions.

Former Member
0 Kudos

Hi Jason,

I just faced the same problems as you do so let me give you a brief desription of our solution.

My problem is that within the code how I can detect which of the screens was being edited (Account/contact/employee) so that I can then set the Grouping field, if blank.

The BADI only will work for all the viewsets that are in the BP_HEAD component. For us this would have been the following controller names: AccountViewSet.do, accountdetails.do, StandardAddress.do and Notes.do. As you can see there are no roles here. What we did was adding the view Roles.AccountRolesEdit to the Viewset BP_HEAD/AccountViewSet.

After you added this you have to switch in the BP_ROLES component in the component workbench and create an component enhancement for the View BP_ROLES/AccountRolesEL. After you've done this you can redefine that method DO_PREPARE_OUTPUT. In there you just call the BADI. See code below for how I did this.


  DATA lr_me      TYPE REF TO cl_bsp_wd_view_controller.

  CALL METHOD super->do_prepare_output
    EXPORTING
      iv_first_time = abap_false.

  TRY.
    lr_me ?= me.
  CATCH cx_sy_move_cast_error.
  ENDTRY.

  CALL METHOD /dpa/cl_im_bp_uiu_defaults=>if_uiu_bp_defaults~get_default_values
    EXPORTING
      iv_first_time = iv_first_time
    CHANGING
      cr_me         = lr_me.

You also have to set the visibility of your attribute ZTYPED_CONTEXT on public.

Now the BADI will also be called for the Roles View in the BP_HEAD component. You determine which View you are currently viewing by it's name, e.g.

 cr_me->controller_name = 'accountrolesel.do'. 

I also need to set the Role as well, so a Contact may have a Role of 'Prospect', for example.

Setting a new role/group works as follows (snippet):


    ASSIGN cr_me->('ZTYPED_CONTEXT') TO <typed_context>.
    IF sy-subrc = 0.
      TRY.
          lr_typed_context ?= <typed_context>.
        CATCH cx_sy_move_cast_error.
      ENDTRY.
      IF lr_typed_context IS BOUND.
        ASSIGN lr_typed_context->('BUILROLES') TO <context_node>.
        IF sy-subrc = 0.
          TRY.
              lr_node ?= <context_node>.
            CATCH cx_sy_move_cast_error.
          ENDTRY.
          IF lr_node IS BOUND.
            TRY.
                lr_coll_wrapper ?= lr_node->collection_wrapper.
              CATCH cx_sy_move_cast_error.
            ENDTRY.
            IF lr_coll_wrapper IS BOUND.
                      lr_entity ?= lr_coll_wrapper->get_current( ).
                      lr_entity->set_property( iv_attr_name = 'PARTNERROLE'
                                               iv_value     = 'YOUR ROLE' ).
                      lr_entity->set_property( iv_attr_name = 'VALID_FROM'
                                               iv_value     = '00010101' ).
                      lr_entity->set_property( iv_attr_name = 'VALID_TO'
                                               iv_value     = '99991231' ).
                      lr_entity->set_property( iv_attr_name = 'PARTNERROLECATEGORY'
                                               iv_value     = 'YOUR ROLE' ).
                      lr_entity->set_property( iv_attr_name = 'RLTITL'
                                               iv_value     = 'NAME OF ROLE' ).
               ENDIF.
                  CATCH cx_sy_move_cast_error.
                  CATCH cx_crm_cic_parameter_error.
                ENDTRY.
MORE ENDIFS.

For grouping it would look something like this:


ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.
    IF sy-subrc = 0.
      TRY.
      lr_typed_context ?= <typed_context>.
      IF lr_typed_context IS BOUND.
        ASSIGN lr_typed_context->('HEADER') TO <context_node>.
        IF sy-subrc = 0.
          lr_node ?= <context_node>.
          IF lr_node IS BOUND.
            lr_coll_wrapper ?= lr_node->collection_wrapper.
            IF lr_coll_wrapper IS BOUND.
              lr_current ?= lr_coll_wrapper->get_current( ).
              CHECK lr_current IS BOUND.

              lr_current->set_property( iv_attr_name = 'BP_GROUP'
                                        iv_value     = 'YOUR GROUPING NUMBER' ).

            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      CATCH cx_sy_move_cast_error.
      CATCH cx_crm_cic_parameter_error.
     ENDTRY.
    ENDIF.

I hope that helps to anwser some of your questions!

Regards,

Georg

Edited by: Georg.Lubrich on Jul 6, 2010 3:07 PM

Former Member
0 Kudos

Georg, That's fantastic, and just what I needed.

Can I ask a really basic question though. What were the definitions you used for <typed_context>, lr_typed_context, <context_node>, lr_node, lr_coll_wrapper,lr_current and lr_entity ?.

Also, why did you need to call the BADI?. I thought the BADI was already being called (somehow) and that we just needed to place code into it, but I can see that you are calling it.

There's very little documentation on this from SAP and when a support call is raised they just point to an SDN thread which mentions the BADI by name, and that's it. This seems to happen a lot with SAP, and yet sometimes I can find indepth articles in CRMexpert, on certain subject, which were actually written by SAP employees, which annoys me when SAP says there is no documentation. Sadly though, even CRMexpert has no articles on this subject, unless they lift the code that you have produced.

Best regards

Jason

Former Member
0 Kudos

Hi Georg and Jason,

Although I like the sollution provided by Georg and it is possibly a good way to provide other views and fields with default data, I don't understand why you would use this sollution for just setting a default role (unless you might need several roles).

The way we solved this is exactly as Georg described for the default grouping, but now for the field BP_ROLE.

So our code (where we set the grouping and role by default) looks like this:

ASSIGN lr_typed_context->('HEADER') TO <context_node>.
      IF sy-subrc = 0.
        TRY.
            lr_node            ?= <context_node>.
          CATCH cx_sy_move_cast_error.  "EC_NOHANDLER
        ENDTRY.
        IF lr_node IS BOUND.
          lr_coll_wrapper ?= lr_node->collection_wrapper.
          IF lr_coll_wrapper IS BOUND.
            TRY.
                lr_current ?= lr_coll_wrapper->get_current( ).
                CHECK lr_current IS BOUND.

*               Set default group
                lr_current->set_property( iv_attr_name = 'BP_GROUP'
                           iv_value = '0001' ).

*               Set default role at creation to "Relation"
                lr_current->set_property( iv_attr_name = 'BP_ROLE'
                           iv_value = 'BUP002' ).

              CATCH cx_sy_move_cast_error.

            ENDTRY.

          ENDIF.
        ENDIF.
      ENDIF.

Now when you save your BP or just hit enter, by default a bp-role "Relation" is created for this BP.

Just wanted to share our sollution, because I expect it to be a very common requirement.

Regards,

Martijn.

Former Member
0 Kudos

Hi Bernard,

Iam on one of the assignment to assign a Country default value. I found this requirement in your posts. But when I copy your code. Im getting a error in the first line.

Error message: Field "'TYPED_CONTEXT" is unknown.

Could you please let me know, how can i get out from this error.

Thanks in advance.

Regards,

Charan

Answers (4)

Answers (4)

shwetha_hs
Employee
Employee
0 Kudos

Hi,

There is a functionality available to create "Application Transactions". Here you can create your own transaction codes and specify what you want to do in those transactions(Example create, change and delete BP) and in which role. If you need more info on this, let me know.

Regards,

Shwetha

Former Member
0 Kudos

Hi Bernard and Somwiya,

I am trying to use this BADI and your code but in the first roe I take error because it says <typed_context> is not defined. What is the definition of this?? What must I add??

Former Member
0 Kudos

Hi experts

I'm also trying to get default value for Roles, and I copied your sample codings.

But the initial statement for asssigning <typed_context>

ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.

does not work, can anyone help?

in debuggun i can see this value is assigned: cr_me->typed_context

regards

*----


  • Default roles

*----


FIELD-SYMBOLS:

<typed_context> TYPE ANY,

<context_node> TYPE ANY.

DATA:

lr_current TYPE REF TO cl_bsp_wd_value_node,

lr_typed_context TYPE REF TO cl_bsp_wd_context,

lr_node TYPE REF TO cl_bsp_wd_context_node,

lr_coll_wrapper TYPE REF TO cl_bsp_wd_collection_wrapper,

W_context TYPE REF TO cl_bsp_wd_view_controller.

.

*web sample dynamic assigment ? does not work

ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.

Former Member
0 Kudos

Hi

If I use the BADI BADI_CRM_BP_UIU_DEFAULTS for setting default to create a direct contactperson with it this works, but if I create a contactperson construction associated with an account, then is dosn't work. Does anyone know why?

Vincent Hamers

Former Member
0 Kudos

Hi experts.

Could you please explain the first instruction and tell me what are the type of the field symbol <typed_context>. and type of lr_typed_context ?

ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.
  IF sy-subrc = 0.
    lr_typed_context ?= <typed_context>.
    IF lr_typed_context IS BOUND.

I've tried with a field symbol of type ANY, but it's never assigned.

Thanks for your help.

Former Member
0 Kudos

Here you go:

DATA:
      lr_current         TYPE REF TO cl_bsp_wd_value_node,
      lr_typed_context   TYPE REF TO cl_bsp_wd_context,
      lr_node            TYPE REF TO cl_bsp_wd_context_node,
      lr_coll_wrapper    TYPE REF TO cl_bsp_wd_collection_wrapper.

  FIELD-SYMBOLS:
    <typed_context>            TYPE ANY,
    <context_node>             TYPE ANY.

I just have the problem that for some views CHECK lr_current IS BOUND fails. So for some reason at that point the BADI is called but the node I wanna set the default values for is not bound. That for example applies to the context BUILSHIPPINGTERMS and BUILPRICINGTERMS in my coding while HEADER and STANDARDADDRESS works just fine. Why is that so?

Former Member
0 Kudos

Hi experts

I'm also trying to get default value for Roles, and I copied your sample codings.

But the initial statement for asssigning <typed_context>

ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.

does not work, can anyone help?

in debuggun i can see this value is assigned: cr_me->typed_context

regards

*----


  • Default roles

*----


FIELD-SYMBOLS:

<typed_context> TYPE ANY,

<context_node> TYPE ANY.

DATA:

lr_current TYPE REF TO cl_bsp_wd_value_node,

lr_typed_context TYPE REF TO cl_bsp_wd_context,

lr_node TYPE REF TO cl_bsp_wd_context_node,

lr_coll_wrapper TYPE REF TO cl_bsp_wd_collection_wrapper,

W_context TYPE REF TO cl_bsp_wd_view_controller.

.

*web sample dynamic assigment ? does not work

ASSIGN cr_me->('TYPED_CONTEXT') TO <typed_context>.

Former Member
0 Kudos

Did you get your code to work?

I am attempting to default the Role and Groupings and have found myself a little lost.

I inserted a break-point (external) in my BADI implementation, but when creating a s new Corporate Account I find that this code is not being exected, or the break point is not being triggered. The implementation is active.

Anyone?

Jason