cancel
Showing results for 
Search instead for 
Did you mean: 

BADI to check and limit the Completed Status of Complaint with message...

former_member214131
Active Contributor
0 Kudos

METHOD if_ex_crm_order_status~before_change.

CONSTANTS: true TYPE crmt_boolean VALUE 'X'.

CONSTANTS: c_bt_complaint TYPE crmv_proc_type-process_type VALUE 'YRMC'.

DATA:lv_guid TYPE crmt_object_guid.

DATA: lt_guids TYPE crmt_object_guid_tab.

DATA: lt_orderadm_h TYPE crmt_orderadm_h_wrkt,

ls_orderadm_h TYPE crmt_orderadm_h_wrk.

DATA: l_crmt_partner_external_wrkt TYPE crmt_partner_external_wrkt.

DATA: ls_crmt_partner_external_wrkt LIKE LINE OF l_crmt_partner_external_wrkt.

DATA: ls_but000 TYPE but000.

DATA: l_partner TYPE bu_partner.

DATA: l_uname TYPE syuname.

DATA: ls_idno TYPE bal_s_idno,

lr_idno TYPE bal_r_idno.

DATA: l_user_flag TYPE flag.

CLEAR: lt_guids, lv_guid.

lv_guid = is_status_wrk-guid.

ls_idno-low-msgid = 'Z08S1_OSS'.

ls_idno-high-msgid = 'Z08S1_OSS'.

ls_idno-low-msgno = '001'.

ls_idno-high-msgno = '001'.

ls_idno-sign = 'I'.

ls_idno-option = 'BT'.

APPEND ls_idno TO lr_idno.

CALL FUNCTION 'CRM_MESSAGES_DELETE'

EXPORTING

it_r_msgidno = lr_idno

iv_ref_object = lv_guid

iv_ref_kind = 'A'

iv_caller_name = 'PARTNER'

EXCEPTIONS

appl_log_error = 1

OTHERS = 2

.

CALL FUNCTION 'CRM_MESSAGE_COLLECT'

EXPORTING

iv_caller_name = 'PARTNER'

iv_ref_object = lv_guid

iv_ref_kind = 'A'

iv_msgno = '001'

iv_msgid = 'Z08S1_OSS'

iv_msgty = 'I'

EXCEPTIONS

not_found = 1

appl_log_error = 2

OTHERS = 3

.

IF sy-subrc <> 0.

ENDIF.

INSERT lv_guid INTO TABLE lt_guids.

CLEAR: lt_orderadm_h.

CLEAR: lt_orderadm_h[].

CALL FUNCTION 'CRM_ORDER_READ'

EXPORTING

it_header_guid = lt_guids

iv_no_auth_check = true

IMPORTING

et_orderadm_h = lt_orderadm_h

EXCEPTIONS

document_not_found = 1

error_occurred = 2

document_locked = 3

no_change_authority = 4

no_display_authority = 5

no_change_allowed = 6

OTHERS = 7

.

IF sy-subrc = 0.

IF NOT lt_orderadm_h IS INITIAL.

READ TABLE lt_orderadm_h INTO ls_orderadm_h INDEX 1.

IF sy-subrc = 0.

IF ls_orderadm_h-process_type = c_bt_complaint.

IF ls_orderadm_h-created_by <> sy-uname.

l_user_flag = 'X'.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

IF l_user_flag = 'X'.

IF is_status_wrk-check_only EQ 'X'.

RAISE not_allowed.

ENDIF.

ENDIF.

ENDMETHOD.

Dear experts,

We have the following requirement:

The complaint (Transaction type: ) is to be checked for the creator & if the creator matches with the logon user then only the complaint can be set to Completed Status. For this we have used following:

Definition Name: CRM_ORDER_STATUS ; Interface: BEFORE_CHANGE. Status profile: CRMCOMPL: Status: E0005

Also we need to display a message "Only Complaint creator can close it by setting to Completed Status." when any user accesses the complaint either in display / edit mode.

The code is indicated as above.

Now The problem is that the message is getting diaplayed only in display mode and not in edit mode.

can anyone suggest.

Best Regards, Murugesh

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member214131
Active Contributor
0 Kudos
METHOD if_ex_crm_order_status~before_change.
CONSTANTS: true TYPE crmt_boolean VALUE 'X'.
CONSTANTS: c_bt_complaint TYPE crmv_proc_type-process_type VALUE 'YRMC'.
DATA:lv_guid TYPE crmt_object_guid.
DATA: lt_guids      TYPE  crmt_object_guid_tab.
DATA: lt_orderadm_h TYPE  crmt_orderadm_h_wrkt,
ls_orderadm_h TYPE  crmt_orderadm_h_wrk.
DATA: l_crmt_partner_external_wrkt TYPE crmt_partner_external_wrkt.
DATA: ls_crmt_partner_external_wrkt LIKE LINE OF l_crmt_partner_external_wrkt.
DATA: ls_but000 TYPE but000.
DATA: l_partner TYPE bu_partner.
DATA: l_uname TYPE  syuname.
DATA: ls_idno TYPE bal_s_idno,
lr_idno TYPE bal_r_idno.
DATA: l_user_flag TYPE flag.
CLEAR: lt_guids, lv_guid.
lv_guid = is_status_wrk-guid.
ls_idno-low-msgid  = 'Z08S1_OSS'.
ls_idno-high-msgid = 'Z08S1_OSS'.
ls_idno-low-msgno = '001'.
ls_idno-high-msgno = '001'.
ls_idno-sign = 'I'.
ls_idno-option     = 'BT'.
APPEND ls_idno TO lr_idno.
CALL FUNCTION 'CRM_MESSAGES_DELETE'
EXPORTING
it_r_msgidno =  lr_idno
iv_ref_object = lv_guid
iv_ref_kind = 'A'
iv_caller_name = 'PARTNER'
EXCEPTIONS
appl_log_error = 1
OTHERS = 2
.
CALL FUNCTION 'CRM_MESSAGE_COLLECT'
EXPORTING
iv_caller_name = 'PARTNER'
iv_ref_object = lv_guid
iv_ref_kind = 'A'
iv_msgno = '001'
iv_msgid = 'Z08S1_OSS'
iv_msgty = 'I'
EXCEPTIONS
not_found = 1
appl_log_error = 2
OTHERS = 3
.
IF sy-subrc <> 0.
ENDIF.
INSERT lv_guid INTO TABLE lt_guids.
CLEAR: lt_orderadm_h.
CLEAR: lt_orderadm_h[].
CALL FUNCTION 'CRM_ORDER_READ'
EXPORTING
it_header_guid = lt_guids
iv_no_auth_check = true
IMPORTING
et_orderadm_h = lt_orderadm_h
EXCEPTIONS
document_not_found = 1
error_occurred = 2
document_locked = 3
no_change_authority = 4
no_display_authority = 5
no_change_allowed = 6
OTHERS = 7
.
IF sy-subrc = 0.
IF NOT lt_orderadm_h IS INITIAL.
READ TABLE lt_orderadm_h INTO ls_orderadm_h INDEX 1.
IF sy-subrc = 0.
IF ls_orderadm_h-process_type = c_bt_complaint.
IF ls_orderadm_h-created_by <> sy-uname.
l_user_flag = 'X'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
IF l_user_flag = 'X'.
IF is_status_wrk-check_only EQ 'X'.
RAISE not_allowed.
ENDIF.
ENDIF.
ENDMETHOD.
former_member214131
Active Contributor
0 Kudos

Dear experts,

We have the following requirement: The complaint (Transaction type: YRMC ) is to be checked for the creator & if the creator matches with the logon user then only the complaint can be set to Completed Status.

For this we have used following:

Definition Name: CRM_ORDER_STATUS ; Interface: BEFORE_CHANGE. Status profile: CRMCOMPL: Status: E0005

Also we need to display a message "Only Complaint creator can close it by setting to Completed Status." when any user accesses the complaint either in display / edit mode.

The code is indicated as above.

Now The problem is that the message is getting diaplayed only in display mode and not in edit mode.

can anyone suggest.

Also the BADI is getting called successively more than once, can we restrice it to one execution for better performance? Does any one has idea how to do this?

Best Regards, Murugesh

rb
Active Participant
0 Kudos

The badi methode before_change is called every time for each status in your filter when the status is a possible selection in a drop down. So reduce the number of calls is not really possible i think.

Sure the message is only shown in display mode and not the other way around? I would thought the badi is called when your are goind to edit the status aka open the complaint in edit mode.

Are You using sapgui or webui?

former_member214131
Active Contributor
0 Kudos

Dear Richard Brünning,

Thanks for the response.

The information message which is displayed appears only in the display mode and not when I get into Edit mode. Not sure why this behaviour. I want to display the same message in edit mode also.

I am using Web UI for the messages.

Best Regards, Murugesh