Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

C4C

How to view a user's assigned organizational unit ID:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

See the assigned organization name in the Organization Data area of ​​Employee, as shown by the red underline in the following figure:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

The current requirement is to use ABSL to obtain the Organization Unit information assigned by the currently logged-in user. For example, to log in with WANGJERRY37, take out the Department name PMLS shown in the following figure:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

Specific implementation: Create a new custom BO and use the field DepartmentName to store the value to be taken:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

Then create an AfterLoading script file with the following code:


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

Assuming that the Organization Unit ID assigned by Jerry Wang is 50000732, use the following report to print out this ID:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM


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.

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

The final call is this function module:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM
To get more Jerry's original technical articles, please follow the public account "Wang Zixi" or scan the QR code below:

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

Obtain the Organization Unit information assigned by the currently logged-in user in C4C and CRM

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324735414&siteId=291194637