Display Custom Message Based on some Attribute Conditions in Web UI.
Hi Everyone,
I would like do some Knowledge Transfer on how can we actually pop-up some custom message based on some conditions in Web-UI level.
Think about a scenario where in we have to pop-up some custom messages based on the certain fields value in relation with Status of the Status field.
Example : We’ll take the SERVICEPRO business role , here we have two field 1) STATUS 2) REFERENCE DATE.
Condition : When the Status field is set to ” Completed ” status , while saving the system should check whether the Reference Date Field have value or not. If the Reference Date field have value in it than it should be successfully saved ,but if the field is empty then it should pop-up a message saying “Reference Date is Initial “.
Note : The message should pop-up only if the Status field is set to ” Completed ” status.
Solution : Check for the SAVE event hander in overview page of corresponding BT Component . First enhance the component, View then this following Event.(Copy the code in event before enhancing it)
Debug to check for the variables ex: lr_ent which refer to CL_CRM_BOL_ENTITY as like which entity falls under this variable. Check the field 1 and field 2 entities and which is the parent entity of the both entity. Since in our example of BT all the entities comes under BTOrder –> BTAdminH from there all the other related entities.
In our example STATUS comes under BTSTATUS entity and REFERENCE DATE comes under BTSALESET entity.
The Hierarchy goes by this way for BT related Components Entities.
Lets assume in lr_ent vriable we have the value BTOrder. Since the field status comes under entity BTStatus which is under BTAdminH entity. So to solve the problem we use the method Get_Related_entity ( ) of class CL_CRM_BOL_ENTITY to find the child entity with the help of the export parameter iv_relation_name where we will give the relation name which actually relate prent entity with child entity.
CALL METHOD lr_ent->get_related_entity
EXPORTING
iv_relation_name = ‘BTOrderHeader’
* iv_mode = NORMAL
RECEIVING
rv_result = lr_ent1.
Here BTOrderHeader is the relation name through which we can identify the child entity and store in variable lr_ent1 which also belong to cl_crm_bol_entity ( ).In our example BTAdminH get stored. since STATUS field comes under BTStatus call the same method again but now the result will store under another variable lo_entity which refer to class If_bol_bo_property_access ( ) since now we’ll use this variable as reference to access method get_property_as_value ( ) which is an interface method as mentioned earlier using which we can find the value present in the attribute we just identified.
CALL METHOD lo_entity1->get_property_as_value
EXPORTING
iv_attr_name = ‘STATUS’
IMPORTING
ev_result = lv_ref.
Here the value gets stored in the variable lv_ref which is of type Data Element of that particular attribute.
SOURCE CODE:
lr_ent1 TYPE REF TO cl_crm_bol_entity,
lr_ent2 TYPE REF TO cl_crm_bol_entity, ” Status.
lo_entity1 TYPE REF TO if_bol_bo_property_access,
lo_entity2 TYPE REF TO if_bol_bo_property_access,
lv_ref1 TYPE crm_j_status,
lv_ref2 TYPE crmt_po_date_sold,
lv_msg TYPE REF TO cl_bsp_wd_message_service.
To find BTAdminH.
CALL METHOD lr_ent->get_related_entity
EXPORTING
iv_relation_name = ‘BTOrderHeader’
* iv_mode = NORMAL
RECEIVING
rv_result = lr_ent1
.
To find BTStatus.
CALL METHOD lr_ent1->get_related_entity
EXPORTING
iv_relation_name = ‘BTHeaderStatusSet’
* iv_mode = NORMAL
RECEIVING
rv_result = lo_entity1
.
To find the value of STATUS field.
CALL METHOD lo_entity1->get_property_as_value
EXPORTING
iv_attr_name = ‘STATUS ‘
IMPORTING
ev_result = lv_ref1.
CALL METHOD lr_ent1->get_related_entity
EXPORTING
iv_relation_name = ‘BTHeaderSalesSet’
* iv_mode = NORMAL
RECEIVING
rv_result = lo_entity2
.
CALL METHOD lo_entity2->get_property_as_value
EXPORTING
iv_attr_name = ‘PO_DATE_SOLD’
IMPORTING
ev_result = lv_ref2.
Check the conditions and display a message.
IF lv_ref1 = ‘Completed’ AND
lv_ref2 IS INITIAL.
lv_msg = cl_bsp_wd_message_service=>get_instance( ).
lv_msg->add_message(
iv_msg_type = ‘E’
iv_msg_id = ‘ZMSGID’
iv_msg_number = 000 ).
ENDIF.
Once the value of STATUS and REFERENCE DATE gets now check for the condition and pop-up a message using the message class cl_bsp_wd_message_service ( )
Result Before enhancing and After Enhancing the component.
Before the error message was developed.
After the error message was developed.
Hope This Document will Help someone in some Situation when come across such situation.
Add Comments if Anybody have doubt regarding this Document.
Thank You & Regards
Rohan
Hi Rohan ,
Thanks , its very useful document ......
Nice document rohan 🙂
Best Regards,
Nikhil Kulkarni
simple and clear...good one