This article explains you how to optimize getting a user from Ultimus OC because if you use the method of GetAllOCMembers defined in Ultimus.OC.OrgChart to identify a user and the solution is running for multiple countries having thousands of employees defined in the Ultimus Organizational Chart, it will take a lot of time as well as it will slow down the loading of the page and end user will get frustrated.
SO lets say you have a business process with following implementation:
1. Designed in Ultimus BPM
2. Integrated with an ASP.NET website
3. Ultimus OC is having the organizational chart/heirarchy defined for multiple countries with a naming convention of Chart Name_CountryName
4. Each chart contains thousands of employees listed
5. A database table is maintained to identify the user country linked with OC.
Structure is like
CountryCode
OCName
6. You want to get the country ISO code of user’s country based on which OC chart the user is found. This ISO code might be used on later stages for some functionality
The function that takes more time is
private string GetUserCountry()
{
string CountryISOCode = string.Empty;
Ultimus.OC.User usr;
Ultimus.OC.User[] usrList;
Ultimus.OC.OrgChart UltOrgChart = new Ultimus.OC.OrgChart();
if (UltOrgChart.GetAllOCMembers(out usrList))
{
for (int i = 0; i < usrList.Length; i++)
{
if ((String.IsNullOrEmpty(Request.Cookies[“UserID”].Value)) || (String.IsNullOrEmpty((usrList[i].strUserName))))
continue;
if (Request.Cookies[“UserID”].Value.ToLower() == usrList[i].strUserName.ToLower())
{
usr = usrList[i];
string[] strChartList = usrList[i].strDepartmentName.Split(‘_’);
string strCountry = strChartList[strChartList.Length – 1];
CountryISOCode = DAL.GetCountryISOCodeAgainstOC(strCountry);//Change the code here to get the data
break;
}
}
}
return CountryISOCode;
}
The improved version is listed below:
private string GetUserCountry()
{
string CountryISOCode = string.Empty;
Ultimus.OC.User usr;
Ultimus.OC.OrgChart UltOrgChart = new Ultimus.OC.OrgChart();
UltOrgChart.FindUser(Request.Cookies[“UserID”].Value, “”, “”, out usr);
Ultimus.OC.Department[] strDepartments;
usr.GetUserDepartments(out strDepartments);
foreach (Ultimus.OC.Department strDepartment in strDepartments)
{
string[] strChartList = strDepartment.strDepartmentName.Split(‘_’);
if (strChartList.Length > 1)
{
string strCountry = strChartList[strChartList.Length – 1];
CountryISOCode = DAL.GetCountryISOCodeAgainstOC(strCountry);//Change the code here to get the data
}
}
return CountryISOCode;
}
The approach being used in the approved version is that instead of
UltOrgChart.GetAllOCMembers(out usrList) //getting all users of OC and then filtering the requested user
we have used
UltOrgChart.FindUser(Request.Cookies[“UserID”].Value, “”, “”, out usr);
which gives the exact user and then you can get a list of his department name and pass it to get the country ISO code.
You can use different variations in this approach to fit into your requirements.