I have to build an error workflow task for a customer, the process should warn the user by email, in case of any errors in the current workflow proces.
I have the users ldap name form the print job.
Have anybody tried to build a javascript in the workflow for ldap/ldaps tasks -to retrieve ldap info like the email address ?
Tried to use a powershell script but it seams like the AD servers does not have that option enabled.
Microsoft ADExplore works fine on the same server with the domain name and a login name.
Most of the javascript I can find on the web, are build for web pages - not exactly the same a script in the workflow.
Here’s a script that I used to query our AD for information about users:
// GET USER INFO FROM ACTIVE DIRECTORY
// See http://www.kouti.com/tables/userattributes.htm for list of RecordSet fields
var connString = "<your connection string>";
var requesterName = "<the user to use to query AD>";
var requesterPW = "<its password>";
var userEmail = "<email of the user you want info on>";
var manager = "";
var userObject = {
manager: "",
managerMail: ""
};
var managerObject = {
email : ""
};
//Search for user's manager
var ldapFilter = "(mail=" + userEmail + ");";
var fieldList = "manager";
var ado = new ActiveXObject("ADODB.Connection");
ado.Provider = "ADSDSOObject";
ado.Properties("User ID") = requesterName;
ado.Properties("Password") = requesterPW;
ado.Properties("Encrypt Password") = true;
ado.Properties("ADSI Flag") = 3;
ado.Open("Search For User");
var rs = ado.Execute(connString + ldapFilter + fieldList + ";subtree");
if(!rs.EOF){
rs.MoveFirst;
userObject.manager = /^CN=([a-zA-Z\sÀ-ÿ]+)/i.exec(rs.Fields("manager").Value)[1];
}
Watch.log("manager= "+userObject.manager,2);
ado.Close;
//Search for manager's email
ado.Open("Search For Email");
ldapFilter = "(CN=" + userObject.manager + ");";
fieldList = "mail";
rs = ado.Execute(connString + ldapFilter + fieldList + ";subtree");
if(!rs.EOF){
rs.MoveFirst;
managerObject.email = rs.Fields("mail").Value;
}
userObject.managerMail = managerObject.email;
ado.Close;
Watch.SetJobinfo(9, JSON.stringify(userObject));
I have really been struggling with this the most of the day, without any results.
The code I have now is this, but it does not work, fails in the execute command - and does not tell me why. (Provider: One or more errors occurred during processing of command.)
// Base data
var connString = “ldap://OU=Onesystem,OU=Organisationer,DC=x1,DC=x2,DC=x3,DC=dk”;
var requesterName = “username”;
var requesterPW = “userpwd”;
var userToFind = “ZYGP”;
//Filter
var SrchCriteria = “(&(objectClass=user)(sAMAccountName=” + userToFind + “))”;
var ldapAttribut = “mail”;
//Connection
var ado = new ActiveXObject(“ADODB.Connection”);
ado.Provider = “ADSDSOObject”;
ado.Properties(“User ID”) = requesterName;
ado.Properties(“Password”) = requesterPW;
ado.Properties(“Encrypt Password”) = true;
ado.Properties(“ADSI Flag”) = 3;
ado.Open(“Search For mail”);