cancel
Showing results for 
Search instead for 
Did you mean: 

Default BP_HEAD_SEARCH ROLE Field?

Former Member
0 Kudos

Hello Experts,

I am trying to default the field "ROLE" of UI COMPONENT: BP_HEAD_SEARCH view BP_HEAD_SEARCH/MainSearch

Context node SEARCH.

I have enhanced the component, the view, and the context node...

I followed this thread:

By redefining the method: DO_INIT_CONTEXT

I am trying to set the ROLE field to have the value "Account" because when our end users do searches I dont want it to display competitors by default, I just want it to display accounts.

So I put in this code:


method DO_INIT_CONTEXT.
CALL METHOD SUPER->DO_INIT_CONTEXT.

DATA: lr_entity TYPE REF TO CL_BSP_WD_VALUE_NODE.
lr_entity ?= me->typed_context->SEARCH->collection_wrapper->get_current( ).
IF lr_entity IS BOUND.
lr_entity->IF_BOL_BO_PROPERTY_ACCESS~set_property( IV_ATTR_NAME = 'ROLE' IV_VALUE = '2' ).
ENDIF.

endmethod.

I don't know too much ABAP so I am wondering why now when I run the search I get a bunch of exceptions:

Context initialization failed in view BP_HEAD_SEARCH/MainSearch of UI Component BP_HEAD_SEARCH

An exception has occurred Exception Class CX_SY_MOVE_CAST_ERROR - Source type \CLASS=CL_CRM_BOL_DQUERY_SERVICE is not compatible, for the purposes of assignment, with target type \CLASS=CL_BSP_WD_VALUE_NODE

Method: ZL_BP_HEAD__MAINSEARCH_IMPL=>DO_INIT_CONTEXT

Source Text Row: 5

Initialization of view BP_HEAD_SEARCH/MainSearch of UI Component BP_HEAD_SEARCH failed

An exception has occurred Exception Class CX_SY_MOVE_CAST_ERROR - Source type \CLASS=CL_CRM_BOL_DQUERY_SERVICE is not compatible, for the purposes of assignment, with target type \CLASS=CL_BSP_WD_VALUE_NODE

Method: ZL_BP_HEAD__MAINSEARCH_IMPL=>DO_INIT_CONTEXT

Source Text Row: 5

Cannot display view MainWindow of UI Component BP_HEAD_SEARCH

An exception has occurred Exception Class CX_SY_MOVE_CAST_ERROR - Source type \CLASS=CL_CRM_BOL_DQUERY_SERVICE is not compatible, for the purposes of assignment, with target type \CLASS=CL_BSP_WD_VALUE_NODE

Method: ZL_BP_HEAD__MAINSEARCH_IMPL=>DO_INIT_CONTEXT

Source Text Row: 5

Can someone please help me with this please!

Accepted Solutions (1)

Accepted Solutions (1)

rb
Active Participant
0 Kudos

You have declared your lr_entity as value node. Try IF_BOL_BO_PROPERTY_ACCESS instead!

DATA: lr_entity TYPE REF TO IF_BOL_BO_PROPERTY_ACCESS.

Then you can set the property and call the method name without the interface name.

Example: lr_entity->set_property_as_string( IV_ATTR_NAME = 'ROLE' IV_VALUE = '2' ).

Former Member
0 Kudos

Hello Richard,

I tried to change my code to this:


method DO_INIT_CONTEXT.
CALL METHOD SUPER->DO_INIT_CONTEXT.

DATA: lr_entity TYPE REF TO IF_BOL_BO_PROPERTY_ACCESS.
lr_entity ?= me->typed_context->SEARCH->collection_wrapper->get_current( ).
IF lr_entity IS BOUND.
lr_entity->set_property_as_string( IV_ATTR_NAME = 'ROLE' IV_VALUE = 'CRM000' ).
ENDIF.
endmethod.

But i still get an error when I go to the accounts search screen:

Context initialization failed in view BP_HEAD_SEARCH/MainSearch of UI Component BP_HEAD_SEARCH

An exception has occurred Exception Class CX_CRM_CIC_PARAMETER_ERROR - Entry parameter of method CL_CRM_BOL_DQUERY_SERVICE->GET_PROPERTY contains value ROLE, which is not allowed

Method: CL_CRM_BOL_DQUERY_SERVICE=>IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY

Source Text Row: 12

Initialization of view BP_HEAD_SEARCH/MainSearch of UI Component BP_HEAD_SEARCH failed

An exception has occurred Exception Class CX_CRM_CIC_PARAMETER_ERROR - Entry parameter of method CL_CRM_BOL_DQUERY_SERVICE->GET_PROPERTY contains value ROLE, which is not allowed

Method: CL_CRM_BOL_DQUERY_SERVICE=>IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY

Source Text Row: 12

Cannot display view MainWindow of UI Component BP_HEAD_SEARCH

An exception has occurred Exception Class CX_CRM_CIC_PARAMETER_ERROR - Entry parameter of method CL_CRM_BOL_DQUERY_SERVICE->GET_PROPERTY contains value ROLE, which is not allowed

Method: CL_CRM_BOL_DQUERY_SERVICE=>IF_BOL_BO_PROPERTY_ACCESS~GET_PROPERTY

Source Text Row: 12

Former Member
0 Kudos

Anyone?

I've tried this as well:


method DO_INIT_CONTEXT.
CALL METHOD SUPER->DO_INIT_CONTEXT.

DATA: lr_entity TYPE REF TO IF_BOL_BO_PROPERTY_ACCESS.
lr_entity ?= me->typed_context->SEARCH->collection_wrapper->get_current( ).
IF lr_entity IS BOUND.
lr_entity->set_property( IV_ATTR_NAME = 'ROLE' IV_VALUE = 'CRMACC' ).
ENDIF.
endmethod.

Same issue, this has to be something rather simple, I've set defaults in the past, but never inside of DO_INIT_CONTEXT for the search screen can someone please help me set the default ROLE attribute name to set the value as 'Account'. This is when our users search the accounts to default the search to only accounts (I dont want to see competitors, etc).

Please someone...

Former Member
0 Kudos

Shobhit / Summit ???

Any experts around to help with this?

All I want to do is default the field ROLE of the context node SEARCH of BP_HEAD_SEARCH to take the value Account (CRMACC).

The error I keep getting is:

Ive debugged it and it goes here: IF_BOL_BO_PROPERTY_ACCESS~SET_PROPERTY

In here it tries to do:

assign component IV_ATTR_NAME of structure ME->QUERY_PARAM_STRUCT_REF->* to <VALUE>.

and then it has a if condition if sy-subrc = 0 ...

But sy-subrc keeps containing the value 4 so it goes into the else and throws this exception:

Exception Class CX_CRM_CIC_PARAMETER_ERROR - Entry parameter of method CL_CRM_BOL_DQUERY_SERVICE->SET_PROPERTY contains value ROLE, which is not allowed

Method: CL_CRM_BOL_DQUERY_SERVICE=>IF_BOL_BO_PROPERTY_ACCESS~SET_PROPERTY

Source Text Row: 11

Can anyone help me figure this out?

Former Member
0 Kudos

This was not working so I found this thread:

And ARUN said to use the GET_VALUE1 / SET_VALUE1 ...

So I tried this:


method GET_VALUE1.
*CALL METHOD SUPER->GET_VALUE1
*  EXPORTING
*    ATTRIBUTE_PATH =
**    ITERATOR       =
*  RECEIVING
*    VALUE          =
*    .

* Get current criterion
  data: criterion type ref to if_bol_bo_property_access.
  if iterator is bound.
    criterion = iterator->get_current( ).
  else.
    criterion = me->parameter_collection->get_current( ).
  endif.

* Set its low value from user input
  try.
      data: lv_value type string.
      lv_value =
         me->convert_value_from_string( iv_string = value
                                        iv_criterion = criterion ).
      criterion->set_property( iv_attr_name = 'LOW'
                               iv_value = lv_value ).       "#EC NOTEXT
    cleanup.
*     Keep buggy user input for correction
      criterion->set_property( iv_attr_name = 'LOW'
                               iv_value = value ).          "#EC NOTEXT
  endtry.

* Set the default value for RESP_AREA
 data: lv_attr_name type string.
  lv_attr_name =  criterion->get_property_as_string( 'ATTR_NAME' ).
if lv_attr_name eq 'ROLE'.
  criterion->set_property( iv_attr_name = 'LOW' iv_value = 'CRMACC' ).
Endif.

endmethod.

I dont get an exception but the value does not change. I tried debugging it and it goes into set property but the value is never changed....???

former_member214667
Contributor
0 Kudos

Hi Jon,

The easiest way to default the role field to some value would be to add it as a search criteria. Try the following code :

DATA lr_qs TYPE REF TO cl_crm_bol_dquery_service.

lr_qs ?= me->typed_context->search->collection_wrapper->get_current( ).

lr_qs->add_selection_param(

iv_attr_name = 'ROLE'

iv_sign = 'I'

iv_option = 'EQ'

iv_low = 'CRMACC'

).

Best Regards,

Shiromani

rb
Active Participant
0 Kudos

Ok second try, i have look into it and would try somthing like this in the DO_INIT_CONTEXT. You might want add some CHECKs etc.

DATA lr_entity           TYPE REF TO cl_crm_bol_dquery_service.
  DATA lr_col              TYPE REF TO if_bol_bo_col.
  DATA lr_param            TYPE REF TO if_bol_bo_property_access.

" First get the dyn query object
lr_entity ?= me->typed_context->search->collection_wrapper->get_current( ).

" Get the selection params
 lr_col = lr_entity->get_selection_params( ).

lr_param = lr_col->get_first( ).

 WHILE lr_param IS BOUND.
      IF lr_param->get_property_as_string( 'ATTR_NAME') = 'ROLE'.
         lr_param->set_property( iv_attr_name = 'LOW' iv_value = 'YOURROLE' ).
      ENDIF.
 ENDWHILE.

Former Member
0 Kudos

This does not work either :(....

I believe this is very similiar to the code I posted for the get_value1

The code does not throw any error it just does not set the default value...

I am uncertain why this is the case...

Former Member
0 Kudos

@Shiromani Sharma,

Yours would work however, if I did that I would lose all other parameters on the screen and that is not good :(.

Is there a way to just modify the existing Role parameter as I am trying to do ?

Former Member
0 Kudos

For now I will use what Shiromoni has posted.

nisha_vinod
Advisor
0 Kudos

Hello Jon,

The reason why the role is not defaulted inspite of set_property is because in the list of DDLB values for Role, a blank value is always the first value in the dropdown.

To default CRMACC, try to redefine the method:

GET_DQUERY_VALUEHELPS of the search context node imp, class BP_HEAD__MAINSEARCH_CN00.

Place a breakpoint at this method and have a look at the DDLB options in runtime. Then manipulate this as follows::

CALL METHOD super->get_dquery_valuehelps
    RECEIVING
      rt_result = rt_result.

  FIELD-SYMBOLS: <rs_result> TYPE crms_thtmlb_search_field_info.

  READ TABLE rt_result ASSIGNING <rs_result> WITH KEY field = 'ROLE'.
  IF sy-subrc EQ 0.
    " include logic to delete first blank entry
    " replace blank entry with your value CRMACC
  ENDIF.

Regards,

Nisha

nisha_vinod
Advisor
0 Kudos

Hello Jon,

The reason why the role is not defaulted inspite of set_property is because in the list of DDLB values for Role, a blank value is always the first value in the dropdown.

To default CRMACC, try to redefine the method:

GET_DQUERY_VALUEHELPS of the search context node imp, class BP_HEAD__MAINSEARCH_CN00.

Place a breakpoint at this method and have a look at the DDLB options in runtime. Then manipulate this as follows::

CALL METHOD super->get_dquery_valuehelps
    RECEIVING
      rt_result = rt_result.

  FIELD-SYMBOLS: <rs_result> TYPE crms_thtmlb_search_field_info.

  READ TABLE rt_result ASSIGNING <rs_result> WITH KEY field = 'ROLE'.
  IF sy-subrc EQ 0.
    " include logic to delete first blank entry
    " replace blank entry with your value CRMACC
  ENDIF.

Regards,

Nisha

Former Member
0 Kudos

Shiromani Sharma,

I noticed this kind of did not work, once I leave the accounts search page and come back it readds the same parameter so now it is doubled.

How do I fix this?

Here is my code:


method DO_INIT_CONTEXT.
CALL METHOD SUPER->DO_INIT_CONTEXT. "call parent class
"the below commented did not work to set the role parameter to CRMACC
  "Data: lr_prop type ref to if_bol_bo_property_access.

  "lr_prop ?= me->typed_context->SEARCH->collection_wrapper->get_current( ).

 "if lr_prop is bound.
 "   lr_prop->set_property( iv_attr_name = 'ROLE' iv_value = 'CRMACC' ).
 "endif.

"We add the fields dynamically and assign default values
 DATA: lr_qs TYPE REF TO cl_crm_bol_dquery_service,
      * check if QS already exist

lr_qs ?= me->typed_context->search->collection_wrapper->get_current( ).

"Add Name 1
lr_qs->add_selection_param(
iv_attr_name = 'MC_NAME1'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = ''
).

"Add city
lr_qs->add_selection_param(
iv_attr_name = 'CITY1'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = ''
).

"Add Country
lr_qs->add_selection_param(
iv_attr_name = 'COUNTRY'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = ''
).

"Add Role and default the value (iv_low = CRMACC)
lr_qs->add_selection_param(
iv_attr_name = 'ROLE'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = 'CRMACC'
).

"Add partner
lr_qs->add_selection_param(
iv_attr_name = 'PARTNER'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = ''
).

endmethod.

rb
Active Participant
0 Kudos

I thought my coding should word, mhhhh are you sure that the default you want to set is equal to the key in the drop down?

If the actual value of the attribute is not found in the drop down list the blank line will be shown.

former_member214667
Contributor
0 Kudos

Hi Jon,

Ya that's right. The possibility of duplicate always exists if you just add it as I have mentioned. There are two things you can do:

A. Delete all existing criteria before you add them ( you can do this if you always want the same set of criteria when you load this search )

B. Try to check if criteria already exisst, add new criteria only if they doesn't exist yet ( you can do this if you want to retain old criteria selected and just add extra criteria needed by your requirement ).

A can be done as follows:

Before you call the add_selection_param() methods, clear query service as follows:


lr_qs->clear_selection_param_values( ).
lr_qs->delete_empty_selection_params( ).

B can be done by the following logic:

1. Get a collection of current selection parameters

2. Iterate on this collection and check if criteria ROLE already exists.

3. If yes, just update its low value

4. If ROLE criteria does not exist yet then add the criteria.

The code to implement this is as follows:


  DATA l_role_set TYPE abap_bool.
  DATA lr_qs      TYPE REF TO cl_crm_bol_dquery_service.
  DATA lr_qs_col  TYPE REF TO if_bol_bo_col.
  DATA lr_param   TYPE REF TO if_bol_bo_property_access.

*   Get selection parameters from query service
    lr_qs ?= me->typed_context->search->collection_wrapper->get_current( ).
    lr_qs_col    ?= lr_qs->get_selection_params( ).
    lr_param = lr_qs_col->get_first( ).

*  Put CRMACC if ROLE criteria is found
    WHILE lr_param IS BOUND.
      l_param = lr_param->get_property_as_string( iv_attr_name = 'ATTR_NAME' ) . "#EC NOTEXT
      IF l_param = 'ROLE'.       
          lr_param->set_property( iv_attr_name = 'LOW' iv_value = 'CRMACC' ).
          l_role_set = abap_true.                           "#EC NOTEXT
          EXIT.     
      ENDIF.
      lr_param = lr_qs_col->get_next( ).
    ENDWHILE.

*   Add criteria ROLE = CRMACC if not added yet
    IF l_role_set = abap_false.
      lr_qs->add_selection_param(
        iv_attr_name  = 'ROLE'
        iv_sign       = 'I'
        iv_option     = 'EQ'
        iv_low        = 'CRMACC'
      ).
    ENDIF.

This will ensure that you add ROLE as criteria only if it is not already added. You can also do the same for all other criteria that you are setting to avoid those being duplicated. You will have to add a flag like l_role_set for each such criteria though and maybe iterate the loop completely.

I suggest that you check the methods of class CL_CRM_BOL_DQUERY_SERVICE to see how search criteria are handled. It is different from how CL_CRM_BOL_ENTITY handles the attributes.

Regards,

Shiromani

Answers (0)