Mobile Application Integration Framework, SAP Field Service Management, SAP Mobile Asset Management, SAP Service and Asset Manager

Integration of SAP Service and Asset Manager (SAM) with SAP Field Service Management (FSM) using the FSM Cloud Connector (proaxia)

SAP Service and Asset Manager (SAM) Mobile Application integrates with SAP Field Service Management (FSM) as part of Field Service Technician persona using Proaxia connector. SAM integrates with SAP FSM planning board to set the current status of the Activity and the Technician location data. Also, updates Mileage and Expense related data captured from the SAM mobile application into FSM cloud system. As part of this Integration, SAM also supports FSM Smartforms and allows the SAM mobile application to download, modify and upload Smartforms assigned to an activity/operation.

Process flow for SAM Integration with FSM

SAP SAM integrated directly with SAP FSM using the Service and Data APIs provided by SAP FSM. However, the underlying objects that need to be updated, (e.g. Service Orders (Service Calls in FSM), Operations (Activities in FSM), Employees (Persons in FSM) are created by the Proaxia connector. Therefore, the following pre-requisites must be implemented for the end-to-end scenarios to work.

Prerequisites:

To execute the supported integration scenarios between SAP SAM and SAP FSM, the following prerequisites must to be met for the integration to work properly:

  1. Enable ‘External Id’ flag under FSM connector Company definition section.
  2. Implement BAdi methods to provide ID mapping between SAM & FSM.

Implementation Details:

The following sections will explain the details on how to implement these prerequisites.

Enable ‘External Id’ flag under FSM connector Company definition settings

From SAP backend system, use menu option of FSM Connector, Customizing –> Objects –> Company –> Company Definition (Transaction Code: /PACG/ECM_COMP).

FSM Connector Company Definition

By enabling the External Id flag, you can switch on sending the External Id from the FSM connector to FSM.

Enable External Id from FSM Connector settings

Implement BAdi methods to provide ID mapping between SAM & FSM:

Mobile Application Integration Framework (MAIF), which supports SAM backend integration features, provides different BAdi options to determine cross-referencing of key fields between FSM Connector and FSM Cloud system. The Badi /MERP/CA_FSM_CROSSREF_BADI is delivered for both ERP & S/4HANA system to support this feature with following interface methods.

BAdi Interface for FSM Id mapping

The following code samples are an example, you may need to make additional adjustments for your environment.

1. Add local method GET_COMPID to determine the FSM company Id. This method required for the GET_EMPLOYEE_IDS BADI method in Step2.

This method returns the following data:

Import Parameter: iv_account TYPE /pacg/ecm_cloudaccount.

Return Parameter: rv_compid TYPE /pacg/ecm_compid.

METHOD get_compid. 
 
    DATA: lv_string1    TYPE string, 
          lv_string2    TYPE string, 
          lv_account    TYPE string, 
          lv_fsmaccount TYPE /pacg/ecm_cloudaccount, 
          lv_fsmcompany TYPE /pacg/ecm_cloudid, 
          lv_compid     TYPE /pacg/ecm_compid, 
          ls_cacc       TYPE /pacg/ecm_cacc. 
 
    lv_account = iv_account. 
 
    SPLIT lv_account AT '&account=' INTO lv_string1 lv_string2. 
    SPLIT lv_string2 AT '&company=' INTO lv_string1 lv_string2. 
 
    lv_fsmaccount = lv_string1. 
    lv_fsmcompany = lv_string2. 
 
 
    ls_cacc = /pacg/ecm_cl_d_access=>get_cloudcomp_definition(  

iv_cloudaccount = lv_fsmaccount 
iv_cloudid      = lv_fsmcompany ). 
 
rv_compid = ls_cacc-compid. 
 
ENDMETHOD.

2. Implement BAdi method /MERP/IF_CA_FSM_CROSSREF_BADI~GET_EMPLOYEE_IDS:

This method is a prerequisite for saving geolocations captured from SAP SAM to the SAP FSM planning and scheduling board.The method must return the FSM internal Employee ID(s) (Field id of the Field Service Management Person entity) based on the personnel number(s) provided.Use the importing parameter IO_ACI_SERVICE to execute a service call to Field Service Management for retrieving the id based on the code in the following code example.

METHOD /merp/if_ca_fsm_crossref_badi~get_employee_ids. 
 
    TYPES: BEGIN OF ty_error, 
             error TYPE string, 
           END OF ty_error. 
 
    TYPES: BEGIN OF ty_fsmitem, 
             id         TYPE string, 
             externalid TYPE string, 
             username   TYPE string, 
           END OF ty_fsmitem. 
 
    TYPES: BEGIN OF ty_persondata, 
             person TYPE ty_fsmitem, 
           END OF ty_persondata. 
 
    DATA: 
      lv_pernr_query TYPE string, 
      ls_oblnk       TYPE /smfnd/sync_d_oblnk_h_upd_str, 
      lv_id          TYPE /smfnd/sync_object_key_dte, 
      lv_url         TYPE string, 
      lv_char_code   TYPE n LENGTH 3, 
      lt_persondata  TYPE STANDARD TABLE OF ty_persondata, 
      ls_persondata  LIKE LINE OF lt_persondata, 
      lt_error       TYPE STANDARD TABLE OF ty_error, 
      ls_error       LIKE LINE OF lt_error, 
      lv_status_code TYPE i, 
      lv_reason      TYPE string, 
      lv_result      TYPE string, 
      lv_raw_data    TYPE xstring, 
      lv_compid      TYPE /pacg/ecm_compid, 
      lv_cloud_uname TYPE /pacg/ecm_cloud_uname, 
      ls_pernr       LIKE LINE OF it_pernr. 
 
    TYPES: BEGIN OF ty_personresp, 
             data LIKE lt_persondata, 
           END OF ty_personresp. 
 
    DATA: ls_personresp TYPE ty_personresp. 
 
    IF io_aci_service IS BOUND. 
      IF it_pernr IS INITIAL. 
        RETURN. 
      ENDIF. 
 
      lv_compid = get_compid( iv_account ). 
 
      LOOP AT it_pernr INTO ls_pernr. 
 
        CLEAR lv_pernr_query. 
 
        IF ls_pernr-low IS NOT INITIAL. 
          TRY. 
              lv_cloud_uname = /pacg/ecm_cl_x_util=>build_cloud_uname( iv_pernr       = ls_pernr-low 
                                                                       iv_compid      = lv_compid ). 
            CATCH /pacg/ecm_cx_main. 
              "No FSM user exists 
              CONTINUE. 
          ENDTRY. 
          CONCATENATE lv_pernr_query 'externalId="' ls_pernr-low '"' INTO lv_pernr_query. 
        ENDIF. 
 
        IF lv_pernr_query IS NOT INITIAL. 
          CONCATENATE '/api/data/v4/Person?dtos=Person.24' '&query=' lv_pernr_query 
                     '&fields=id,externalId,userName' iv_account INTO lv_url. 
 
          CALL METHOD io_aci_service->call_service 
            EXPORTING 
              iv_request_uri    = lv_url 
              iv_request_method = 'GET' 
              it_headers        = it_headers 
            IMPORTING 
              ev_status_code    = lv_status_code 
              ev_reason         = lv_reason 
              ev_result         = lv_result 
              ev_raw_data       = lv_raw_data. 
 
          lv_char_code = lv_status_code. 
          IF lv_char_code CP '4*'. 
            ls_error-error = lv_result. 
            APPEND ls_error TO lt_error. 
          ELSE. 
            /aci/cl_util_json_handler=>deserialize(  EXPORTING json =  lv_result 
                                                     CHANGING  data =  ls_personresp  ). 
            LOOP AT ls_personresp-data INTO ls_persondata. 
              lv_id = ls_persondata-person-id. 
              ls_oblnk-object_type  = 'EMPLOYEE'. 
              ls_oblnk-object_key  = ls_pernr-low. 
              ls_oblnk-ext_object_type  = 'PERSON'. 
              ls_oblnk-ext_object_key  = lv_id. 
              ls_oblnk-sys_comp = 'SAP_FSM'. 
              ls_oblnk-mobile_app = iv_mapp. 
              APPEND ls_oblnk TO et_oblnk. 
              CLEAR ls_oblnk. 
            ENDLOOP. 
          ENDIF. 
        ENDIF. 
      ENDLOOP. 
    ENDIF. 
  ENDMETHOD.

3. Implement the method /MERP/IF_CA_FSM_CROSSREF_BADI~GET_ACTIVITY_ID:

This method is a prerequisite for implementing the relevant status updates from SAP SAM to the SAP FSM planning and scheduling board. This method must return the Field Service Management internal activity ID (the id field of the Field Service Management Activity entity) based on the order and operation number provided.

Use the importing parameter IO_ACI_SERVICE to execute a service call to Field Service Management for retrieving the ID based on the code. See the following code example for more details.

METHOD /merp/if_ca_fsm_crossref_badi~get_activity_id. 
 
    TYPES: BEGIN OF ty_fsmitem, 
             id         TYPE string, 
             externalid TYPE string, 
           END OF ty_fsmitem. 
 
    TYPES: BEGIN OF ty_error, 
             error TYPE string, 
           END OF ty_error. 
 
    TYPES: BEGIN OF ty_actdata, 
             activity TYPE ty_fsmitem, 
           END OF ty_actdata. 
 
    DATA: 
      lv_act_query   TYPE string, 
      lv_id          TYPE /smfnd/sync_object_key_dte, 
      lv_url         TYPE string, 
      lv_char_code   TYPE n LENGTH 3, 
      lt_actnr       TYPE STANDARD TABLE OF /pacg/ecm_actnr, 
      lv_actnr       TYPE /pacg/ecm_actnr, 
      lv_object_key  TYPE /smfnd/sync_object_key_dte, 
      lt_error       TYPE STANDARD TABLE OF ty_error, 
      ls_error       LIKE LINE OF lt_error, 
      lt_actdata     TYPE STANDARD TABLE OF ty_actdata, 
      ls_actdata     LIKE LINE OF lt_actdata, 
      lv_status_code TYPE i, 
      lv_reason      TYPE string, 
      lv_result      TYPE string, 
      lv_raw_data    TYPE xstring, 
      lv_aufnr_len   TYPE i, 
      lo_descr       TYPE REF TO cl_abap_elemdescr, 
      ls_aufnr_dfies TYPE dfies. 
 
    TYPES: BEGIN OF ty_actresp, 
             data LIKE lt_actdata, 
           END OF ty_actresp. 
 
    DATA: ls_actresp TYPE ty_actresp. 
 
    IF io_aci_service IS BOUND. 
      IF iv_aufnr IS INITIAL OR iv_vornr IS INITIAL. 
        RETURN. 
      ENDIF. 
 
      lv_object_key = iv_aufnr. 
      lo_descr ?= cl_abap_elemdescr=>describe_by_data( iv_aufnr ). 
      ls_aufnr_dfies = lo_descr->get_ddic_field( ). 
      lv_aufnr_len = ls_aufnr_dfies-leng. 
      lv_object_key+lv_aufnr_len = iv_vornr. 
 
      "Get all activitties for order operation 
      SELECT actnr INTO TABLE lt_actnr FROM /pacg/ecm_acti WHERE aufnr = iv_aufnr AND vornr = iv_vornr. 
 
      "Get the newest activity 
      SORT lt_actnr DESCENDING. 
      READ TABLE lt_actnr INTO lv_actnr INDEX 1. 
      IF sy-subrc IS NOT INITIAL. 
        RETURN. 
      ENDIF. 
 
      CONCATENATE lv_act_query 'externalId="' lv_actnr '"' INTO lv_act_query. 
 
      IF lv_actnr IS NOT INITIAL. 
        CONCATENATE '/api/data/v4/Activity?dtos=Activity.39' '&query=' lv_act_query '&fields=id,externalId' iv_account INTO lv_url. 
 
        CALL METHOD io_aci_service->call_service 
          EXPORTING 
            iv_request_uri    = lv_url 
            iv_request_method = 'GET' 
            it_headers        = it_headers 
          IMPORTING 
            ev_status_code    = lv_status_code 
            ev_reason         = lv_reason 
            ev_result         = lv_result 
            ev_raw_data       = lv_raw_data. 
 
        lv_char_code = lv_status_code. 
        IF lv_char_code CP '4*'. 
          ls_error-error = lv_result. 
          APPEND ls_error TO lt_error. 
        ELSE. 
          /aci/cl_util_json_handler=>deserialize(  EXPORTING json =  lv_result 
                                                   CHANGING  data =  ls_actresp  ). 
          LOOP AT ls_actresp-data INTO ls_actdata. 
            lv_id = ls_actdata-activity-id. 
            es_oblnk-object_type  = 'OPERATION'. 
            es_oblnk-object_key  = lv_object_key. 
            es_oblnk-ext_object_type  = 'ACTIVITY'. 
            es_oblnk-ext_object_key  = lv_id. 
            es_oblnk-sys_comp = 'SAP_FSM'. 
            es_oblnk-mobile_app = iv_mapp. 

      ev_id = ls_actdata-activity-id. 
            EXIT. 
          ENDLOOP. 
        ENDIF. 
      ENDIF. 
    ENDIF. 
 
  ENDMETHOD.

4. Implement the method /MERP/IF_CA_FSM_CROSSREF_BADI~GET_SERV_ASSIGN_ID:

This method is a prerequisite for implementing relevant status updates from SAP SAM to the SAP FSM planning and scheduling board. The method must return the FSM internal activity ID (the idfield of the Field Service Management Activity entry) based on the order and operation number provided.Use the QUERY_FSM_SERVICEASSIGN method from the /MERP/CL_CA_FSM_INTEGRATION class to get this value based on the following code example.

METHOD /merp/if_ca_fsm_crossref_badi~get_serv_assign_id. 
    DATA lref_fsm_integration TYPE REF TO /merp/cl_ca_fsm_integration. 
 
    TRY. 
        " Create FSM object 
        CREATE OBJECT lref_fsm_integration 
          EXPORTING 
            iv_mapp = iv_mapp. 
      CATCH /merp/cx_core_exception_gen INTO DATA(lref_badi_exception). 
        RETURN. 
    ENDTRY. 
    " Fetch Service Assignment from FSM if it exists 
    lref_fsm_integration->query_fsm_serviceassign( 
      EXPORTING 
        iv_aufnr       = iv_aufnr 
        iv_vornr       = iv_vornr 
        iv_activity_id = iv_activity_id 
      IMPORTING 
        ev_id          = ev_id 
        ev_activity_id = ev_activity_id 
        es_oblnk       = es_oblnk 
        ). 
  ENDMETHOD.

5. Implement the method /MERP/IF_CA_FSM_CROSSREF_BADI~GET~GET_SERV_ASSIGN_STATUS_ID:

This method is a prerequisite for implementing relevant status updates from SAP SAM to the SAP FSM planning and scheduling board. Use the QUERY_FSM_SERVICEASSIGNSTATUS method from the /MERP/CL_CA_FSM_INTEGRATION class to get this value based on the following code example.

METHOD /merp/if_ca_fsm_crossref_badi~get_serv_assign_status_id. 
    DATA lref_fsm_integration TYPE REF TO /merp/cl_ca_fsm_integration. 
 
    TRY. 
        " Create FSM object 
        CREATE OBJECT lref_fsm_integration 
          EXPORTING 
            iv_mapp = iv_mapp. 
      CATCH /merp/cx_core_exception_gen INTO DATA(lref_badi_exception). 
        RETURN. 
    ENDTRY. 
 
    lref_fsm_integration->query_fsm_serviceassignstatus( 
        EXPORTING 
          iv_aufnr       = iv_aufnr 
          iv_vornr       = iv_vornr 
          iv_activity_id = iv_activity_id 
        IMPORTING 
          ev_id          = ev_id 
          es_oblnk       = es_oblnk 
          ). 
ENDMETHOD.
Rating: 0 / 5 (0 votes)