C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

注销發表於2018-04-06

C4C

如何檢視某個使用者分配的組織單元ID:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

在Employee的Organization Data區域內看到分配的組織名稱,如下圖紅色下劃線所示:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

現在的需求就是使用ABSL獲取當前登入使用者分配的Organization Unit資訊,例如用WANGJERRY37登入,則取出下圖顯示的Department name PMLS:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊
C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

具體實現:新建一個custom BO,使用欄位DepartmentName儲存這個待取的值:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

然後建立AfterLoading script file,使用如下程式碼:

 import ABSL; import AP.PC.IdentityManagement.Global; import AP.FO.BusinessPartner.Global; var queryByIdentityUUID = Identity.QueryByElements; var queryByIdentityUUIDParameter = queryByIdentityUUID.CreateSelectionParams(); var queryByEmployeeBPUUID = Employee.QueryByIdentification; var queryByEmployeeBPUUIDParameter = queryByEmployeeBPUUID.CreateSelectionParams(); if ( this.DepartmentName.IsInitial()){ var id = Context.GetCurrentIdentityUUID().content;
    queryByIdentityUUIDParameter.Add( queryByIdentityUUID.UUID.content, "I", "EQ", id.ToString() ); var result = queryByIdentityUUID.Execute(queryByIdentityUUIDParameter); var first = result.GetFirst(); // points to identity instance var person = first.Person; var bpUUId = person.UUID.content;
    queryByEmployeeBPUUIDParameter.Add( queryByEmployeeBPUUID.UUID.content, "I", "EQ", bpUUId.ToString()); var employeeQueryResult = queryByEmployeeBPUUID.Execute(queryByEmployeeBPUUIDParameter); var EmployeeQueryResultCurrent = employeeQueryResult.GetFirst(); var assignedOrg = EmployeeQueryResultCurrent.OrganisationalUnitAssignment.GetFirst(); var org = assignedOrg.ToRoot; // readOnly in AfterLoading event this.DepartmentName  = org.NameAndAddress.AddressSnapshot.NameSuitableForLogonLanguage.GetFirst().Name.SecondLineName;
} 

CRM

假設Jerry Wang分配的Organization Unit ID為50000732,使用下列report列印出這個ID:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊
 PARAMETERS: id TYPE but000-partner OBLIGATORY DEFAULT '4031140'.
DATA: lo_core                TYPE REF TO cl_crm_bol_core,
      lo_collection          TYPE REF TO if_bol_entity_col,
      lo_root_entity         TYPE REF TO cl_crm_bol_entity,
      lv_query_name          TYPE crmt_ext_obj_name,
      lt_selection_parameter TYPE genilt_selection_parameter_tab,
      ls_selection_parameter TYPE genilt_selection_parameter,
      ls_query_parameters    TYPE genilt_query_parameters,
      lv_size                TYPE i.
START-OF-SELECTION.
  ls_selection_parameter-attr_name = 'PARTNER'.
  ls_selection_parameter-option = 'EQ'.
  ls_selection_parameter-sign = 'I'.
  ls_selection_parameter-low =  id.
  APPEND ls_selection_parameter TO lt_selection_parameter.
  ls_query_parameters-max_hits = 1. lo_core = cl_crm_bol_core=>get_instance( ).
  lo_core->load_component_set( 'PROD_ALL' ).
  lv_query_name = 'BuilEmpAdvancedSearch'.
  lo_collection = lo_core->dquery(
      iv_query_name               = lv_query_name
      it_selection_parameters            = lt_selection_parameter
      is_query_parameters                = ls_query_parameters ).
  DATA(lo_result) = lo_collection->get_first( ).
  ASSERT lo_result IS NOT INITIAL.
  WRITE: / 'Org unit id: ', lo_result->get_property_as_string( 'ORGEH' ) COLOR COL_NEGATIVE. 
C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

最終呼叫的是這個function module:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

要獲取更多Jerry的原創技術文章,請關注公眾號"汪子熙"或者掃描下面二維碼:

C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊
C4C和CRM裡獲取當前登入使用者分配的Organization Unit資訊

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2154192/,如需轉載,請註明出處,否則將追究法律責任。

相關文章