Getting AD destination from email address

  • 27 March 2007
  • 2 replies
  • 1 view

Badge +2
Hi

I want to resolve the AD user for dynamic destinations, but I only have the Email address exposed to the process. How do i do it? The DSHelper is supposed to help me, but I cannot seem to get it to work correctly.

public void Main(ref DestinationRuleContext K2) {

K2.ResolveQueuesToUsers = true;

SourceCode.K2Utilities.DSHelper oDSH = new SourceCode.K2Utilities.DSHelper(SourceCode.K2Utilities.DSHelper.DSHelperNewOptionsEnum.DefaultLDAPDomain);
System.DirectoryServices.DirectoryEntry oDEManager;
string sManager;
bool bAllTrue = true;
CDest1 oDest1 = new CDest1();
oDest1.Main(ref K2);
if (oDest1.IsSuccess == true) {
//== sendto
K2.Destinations.Add(DestinationType.User, @"NO
solheim");

if (bAllTrue == false) return;
}
SourceCode.K2Utilities.DSHelper oDSH = new SourceCode.K2Utilities.DSHelper(SourceCode.K2Utilities.DSHelper.DSHelperNewOptionsEnum.DefaultLDAPDomain);
System.DirectoryServices.DirectoryEntry oDEManager;
string sManager;
bool bAllTrue = true;
CDest1 oDest1 = new CDest1();
oDest1.Main(ref K2);
if (oDest1.IsSuccess == true) {
//== sendto
K2.Destinations.Add(DestinationType.User, oDSH.GetUser("email",K2.ProcessInstance.DataFields["AssignedTo"].Value.ToString()));
if (AllTrue == false) return;

}
}

Regards

Arne

2 replies

Badge +7
Hi,

I actually have never used the getUser() Method but I would maybe try changing from "email" to "mail"

What I usally do is to use my own AD helper implemented in a code module. Sample code below.
It asks for 3 parameters, the first "what credential do i pass (e.g. mail)" the second "the value (e.g. yourname@yourcompany.com)" and the third what do i want to get (e.g. "name")

)
{
var = myCollection.ToString();
}
}
}
catch (Exception ex)
{
ex.Message.ToString();
}
return var;
}
}
Badge +2
using System;

using System.Collections.Generic;

using System.Data;

using System.Net;

using System.Text;

using System.Xml;

using System.DirectoryServices;

using SourceCode.K2Utilities;



namespace Scratch

{

class Program

{

static void Main(string[] args)

{

DSHelper helper = new DSHelper("pegasus");

DirectoryEntry user = helper.GetUser("mail", "administrator@k2.net");



try

{

string dn = helper.GetProperty(user, "distinguishedName");

int uStart = dn.IndexOf("CN=") + 3;

int uLength = dn.IndexOf(",", uStart) - 3;

int dStart = dn.IndexOf("DC=") + 3;

int dLength = dn.IndexOf(",", dStart) - dStart;

string userName = dn.Substring(uStart, uLength);

string domain = dn.Substring(dStart, dLength);

Console.WriteLine(domain + @"" + userName);

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

Console.Read();

}

}

}

Reply