on 10-23-2008 9:49 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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.
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
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???
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
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
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
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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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??
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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>.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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?
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>.
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
User | Count |
---|---|
5 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.