Creating an Employee SmartObject (SmO) is a great business entity to have available for any workflow application in a company. It is very easy to create a SmartObject in the K2 Studio SmO Editor and use the existing K2 Active Directory Service Object.
In 2 or 3 steps, you will be able to create the following SmO (for more details, please see the “SmartObject Integration >> Introduction to SmartObjects | SmartObject Properties Toolbar | SmartObject Method Wizard” topics in the “K2blackpearl.chm” file from your K2 Blackpearl 0803 documentation):
SmartObject Properties

Obviously, you can call your SmO objects methods into your process without writing any code, using the SmartObject Event to associate DataFields with SmO return Properties (for more details, please see the “SmartObject Integration >> K2 SmartObject Event Wizard” topic in the “K2blackpearl.chm” file), or to create some rules in your outcomes. In your .net forms, you can easily use the K2 blackpearl ADO.net Data Provider to request your SmO (for more details, please see the “K2 for Visual Studio >> The .NET Framework Data Provider for K2 SmartObjects” topic in the “K2blackpearl.chm” file) to create for example a DropDownList displaying employees.

Perhaps you do not want to use the ADO.net Data Provider ? Why not :-)… You have the ability to use the SmO API to call your methods. In this case, you need to be aware of a tricky behavior using the Active Directory Service Object: the Property Name visible on your SmartObject Editor isn’t the name you need to use with the API to get the value. This name is actually the display name, and you need to know the real name of the property and that name is the one used in the DirectoryServices namespace. The following sample code shows how to use the GetList SmO method with a filter on the Account Name, including the association between Display Name and Property Name:

 

    using SourceCode.Hosting.Client;

    using SourceCode.SmartObjects.Client;

    using SourceCode.SmartObjects.Client.Filters;

 

    public void getADSmOProp(string myFilterValue)

    {

        // Open a K2 Server connection

        SmartObjectClientServer SmOServer = new SmartObjectClientServer();

        SmOServer.CreateConnection();

        SmOServer.Connection.Open("<MyConnectionString>");

 

        // Get a handle to the ' MyADSmO' SmartObject

        SmartObject soEmployes = SmOServer.GetSmartObject("<MyADSmO>");

        // Specify which method will be called

        SmartListMethod getList = soEmployes.ListMethods["GetList"];

        soEmployes.MethodToExecute = getList.Name;

 

        // Setup the filter

        Contains myFilter = new Contains();

        myFilter.Left = new PropertyExpression("name", PropertyType.Text);

        myFilter.Right = new ValueExpression(myFilterValue, PropertyType.Text);

        getList.Filter = myFilter;

 

        // Call the method which will use the filter

        SmartObjectList soLEmployes = SmOServer.ExecuteList(soEmployes);

 

        string p = "";

        foreach (SmartObject smo in soLEmployes.SmartObjectsList)

        {

          //***** Properties to display

          // SmO Property - Account Name:

          p += smo.Properties["sAMAccountName"].Value;

          // SmO Property - User Friendly Name:

          p += smo.Properties["name"].Value;

          // SmO Property - Unique Name:

          p += smo.Properties["distinguishedName"].Value;

          // SmO Property - Active Directory Object Type:

          p += smo.Properties["objectClass"].Value;

          // SmO Property - Email:

          p += smo.Properties["mail"].Value;

          // SmO Property - Description:

          p += smo.Properties["description"].Value;

          // SmO Property - User Manager:

          p += smo.Properties["manager"].Value;

          // SmO Property - Domain Name:

          p += smo.Properties["domainname"].Value;

          // RMK: Friendly Name is in smo.Properties["<property>"].Metadata.DisplayName

        }

 

        // Close the connection

        SmOServer.Connection.Close();

    }

Important notice: K2 Labs are currently busy working on a new version of the AD Service, so this should be fixed in a next release K2 blackpearl 0806 with optimization of the AD tools.


-- by Jean Cadeau