...by Daniel Szego
quote
"On a long enough timeline we will all become Satoshi Nakamoto.."
Daniel Szego

Thursday, July 10, 2014

Connecting SAP employee information with SharePoint user profile services - Part 2

In the first part of the blog, we have seen how the basic connection with SAP can be set up :
Connecting-SAP-employee-information with SharePoint user profile services Part 1 
Now let we see how the BCS side can be configured :
STEP 2 : Creating BCS. 
1. Create an empty SharePoint 2013 Project in the same solution add a Business Data Connectivity Model to the Project and do not forget to refernce the project of the old command promt application, fo course ony after that you set the project output type to class library :



2. configure in the package, that both the solution dlls and the SAP Connector dlls are deliverd to the GAC (rscp4n.dll, sapnco.dll, sapnco_utils.dll)
3. Add a static Connection class to have a reference on the connection itself :​
    public static class Connection
    {
        public static RfcDestination rfcDest = null;

        static Connection()
        {
            SAPSystemConnect sapCfg = new SAPSystemConnect();
            RfcDestinationManager.RegisterDestinationConfiguration(sapCfg);
            rfcDest = RfcDestinationManager.GetDestination("XXX");
        }
    }​

4. Update the employee to cover the basic properties.
   public partial class EmployeeEntity
    {
        public EmployeeEntity(Employee emp)
        {
            this.Job = emp.Job;
            this.Name = emp.Name;
            this.Organisation = emp.Organisation;
            this.PeronalNr = emp.PeronalNr;
        }
        public EmployeeEntity()
        {
        }
        private string _PeronalNr;
        private string _Name;
        private string _Organisation;
        private string _Job;
        // BAPI_EMPLOYEE_GETLIST - ENAME
        public string Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        // BAPI_EMPLOYEE_GETLIST - ORG_TEXT
        public string Organisation
        {
            get
            {
                return _Organisation;
            }
            set
            {
                _Organisation = value;
            }
        }

        // BAPI_EMPLOYEE_GETLIST - JOB_TEXT
        public string Job
        {
            get
            {
                return _Job;
            }
            set
            {
                _Job = value;
            }
        }
    }
}
5. Implement the finder and specific finder methods to get the employee infromation:
      public static EmployeeEntity ReadItem(string Name)
        {
            Employee e = new Employee();
            EmployeeEntity ret = new EmployeeEntity(e);
            // get all Basic employee information from SAP

            List<Employee> emps = Employee.getAllEmployees(Connection.rfcDest);
            foreach (Employee emp in emps)
            {
                if(Name.ToLower().Contains(emp.Name.ToLower()))
                {
                    ret = new EmployeeEntity(emp);
                }
                if (emp.Name.ToLower().Contains(Name.ToLower()))
                {
                    ret = new EmployeeEntity(emp);
                }
                if (emp.Name.ToLower().Equals(Name.ToLower()))
                {
                    ret = new EmployeeEntity(emp);
                }
            }
            return ret;
        }
 
       public static IEnumerable<EmployeeEntity> ReadList()
        {
            List<EmployeeEntity> ret = new List<EmployeeEntity>();
            // get all Basic employee information from SAP

            List<Employee> emps = Employee.getAllEmployees(Connection.rfcDest);
            foreach (Employee emp in emps)
            {
                ret.Add(new EmployeeEntity(emp));
            }
            return ret;
        }

In this example specific finder is simply the name of an employee, that is pretty much general configured to match. We certainly use the Employee wrapper class that was implemented in the first part of this blog to capture the SAP information, 
6. Configure BCS either with the help of the editor or directly the xml to contain the properties and the Name property as an indexer :


7. After building and deploying, you can test if it works as well, like creating an external list in one of the sites and populating SAPUserProfil EmployeeEntity external type (do not forget giving rights to the external content type at the central administration) :



STEP 3: So, last but not least, the external content type has to be configured in the user profil sync: 
1. In the User Profile Service Application by Configure Syncronisation Connection create a new connection from the type Business Data Connectivity, and configure a matching based on the AccountName or PreferedName (basicaly the specific finder is pretty flexible configured, so all of these conbinations should work). In this example we already have one connection to syncronise the basic accounts and user related information from Active Directory.



2. Create two new properties in the user profile service application for SAP Job and SAP Organisation infromation (like SAPJob2 and SAPOrg2) and configure them to get the information from the newly configured syncronisation connection. 



3. Start a full User Profile syncronisation. 
4. Check if the user profile has got the information in the extended properties, like 


...

The end.