简体   繁体   English

在CRM Dynamics 2011中查询Active Directory

[英]Querying Active Directory in CRM Dynamics 2011

I would like CRM to query the active directory and return all the results it finds for, say, "first name". 我希望CRM查询活动目录并返回它找到的所有结果,例如“名字”。 so, for example: I type in 'Tom' on a field, click a search button and it returns the relevant XML for: 因此,例如:我在一个字段上键入“ Tom”,单击搜索按钮,它返回以下内容的相关XML:

Tom.Smith, Tom.Jones, Tom.Tonks, etc. 汤姆·史密斯,汤姆·琼斯,汤姆·唐克斯等

I've read around and the following code enables me to search against a username, eg 'Tom.Jones' 我已经阅读了一下,下面的代码使我可以搜索用户名,例如“ Tom.Jones”

var oCommand=new RemoteCommand("UserManager","RetrieveADUserProperties");   
if(oCommand!=null)   
{   
  oCommand.SetParameter("domainAccountName","Tom.Jones");   
  var oResult=oCommand.Execute();   
  if(oResult.Success&&!IsNull(oResult.ReturnValue)&&oResult.ReturnValue.length>0)   
  {   
    var firstName = "";   
    var lastName ="";     
    for(
      var oUserXmlDoc=loadXmlDocument(oResult.ReturnValue),
      oNodeList=oUserXmlDoc.documentElement.childNodes,i=0;
      i<oNodeList.length;
      i++      
    )  
    {  
      var oNode=oNodeList.item(i);  
      if (oNode.tagName == "firstname")  
      {  
        firstName = oNode.text;  
      } else if(oNode.tagName == "lastname") {  
        lastName = oNode.text;  
      }  
    }  
  }  
}          

(source: Technocratica ) (来源: Technocratica

but it will only return a result if precisely the correct username has been entered. 但只有输入了正确的用户名,它才会返回结果。

In effect, I need to query something along the lines of: 实际上,我需要查询以下内容:

  oCommand.SetParameter("domainAccountFirstName","Tom.Jones");

but I don't know what CRM/AD is/are looking for on this front. 但我不知道在这方面正在寻找什么CRM / AD。 Does anyone know if there are search terms other than "domainAccountName"? 有人知道“ domainAccountName”以外的搜索词吗?

We had a similar need however we also had extremely high number of users. 我们有类似的需求,但是我们也有非常多的用户。 Our approach involved leveraging CRM by creating a custom “domain contact” entity in CRM and updating the entities nightly. 我们的方法涉及通过在CRM中创建自定义“域联系人”实体并每晚更新实体来利用CRM。 This allowed our end users to use the Quick Find, Views and other tools already in CRM. 这使我们的最终用户可以使用CRM中已经存在的快速查找,视图和其他工具。 Best of all, the end user can use wild cards in their searches. 最重要的是,最终用户可以在搜索中使用通配符。

To facilitate this we ended up writing a separate application that queries AD once a night and populates a SQL database. 为此,我们最终编写了一个单独的应用程序,该应用程序每晚查询一次AD,并填充一个SQL数据库。 Then we use a custom workflow step called from a reoccurring workflow to query the database and update CRM as needed. 然后,我们使用一个自定义工作流步骤(从重复发生的工作流中调用)来查询数据库并根据需要更新CRM。

While the goal was to keep large queries against AD from having an adverse impact to our environment, we ended up giving our end users some great tools with only a small amount of code to maintain. 虽然目标是防止针对AD的大型查询对我们的环境造成不利影响,但最终我们为最终用户提供了一些很好的工具,仅需维护少量的代码。

Upon investigation the SetParameter method can only take a limited number of arguments as its first parameter; 经调查,SetParameter方法只能将有限数量的参数用作其第一个参数; and none of those arguments enable a developer to search for just a first or last name. 这些参数都不能使开发人员仅搜索名字或姓氏。

The easiest option (at least, in my situation) therefore was to write an iframe plugin that runs an LDAP request to AD. 因此,最简单的选择(至少就我而言)是编写一个向AD运行LDAP请求的iframe插件。 Bear in mind that the usual domain rules vis a vis XSS etc. apply in this instance. 请记住,针对XSS等的常规域规则在这种情况下适用。 Anyone relatively new to C# will find comprehensive assistance in writing a useful solution here: 对C#较新的任何人都可以在这里编写有用的解决方案方面获得全面的帮助:

http://msdn.microsoft.com/en-us/library/System.DirectoryServices.aspx http://msdn.microsoft.com/en-us/library/System.DirectoryServices.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM