How to query the Active Directory Web Service - Aruna Akella
in

InfoPath Dev

Aruna Akella

How to query the Active Directory Web Service

The Qdabra Active Directory Web Service supports the following methods:

  • GetMyInfo - gives the Active Directory properties of the currently Logged In user
  • GetUserInfo - gives the Active Directory properties of the specified user name
  • GetManagerAlias - returns the alias for a user's manager if one is set
  • GetEmployeesForManager - returns a list of employees that have a manager with the specified alias
  • FindUsersByName - attempts to find any users with a name matching the specified search string
  • FindUsersByAlias - attempts to find any users with an alias matching the specified search string
  • IsUserMemberOfGroup - returns true if the user is part of the specified group, false otherwise
  • GetGroupsForUser – returns a list of the groups to which the current user belongs.
  • GetMembersOfGroup – returns the alias, and display name of group members.

Let's walk through the steps on setting up a sample form which queries all the above operations.

Design the InfoPath form template

 1.   Open InfoPath and design a new blank form.

    

 2.   Add the following groups and fields in your Main data source:

    

 3.  Add three tables with titles, and place each group’s fields into each of the tables:

    

 4.  Add secondary data connections:

     a.  Go to Tools a Data Connections à Add….

     b.  Create a new connection to receive data from a Web service.

       

       

     c.  Enter the URL: http://<servername>/QdabraWebService/ADUserInfo.asmx where <ServerName> is the location where DBXL is installed.

       

     d.  From the list of operations, select GetGroupsForUser.

       

     e.  Enter the default values:

       

     f.  Check the box that says Automatically retrieve data when the form is opened, then click Finish.

      

 5.  Repeat Steps 2a to 2d to add data connections for the rest of the operations.

 6.  When done, exit the data connections wizard.

Query GetMyInfo

 1.   Configure the MyUserInfo fields:

     a. Double-click on the MyUserName field to display its properties.
 
     b. In the Data tab, click on the fx button to set a default value.
 
     c. In the Insert Formula window, click the Insert Field or Group button.
 
     d. Select the secondary data source GetMyInfo from the data source drop-down.
 
     e. Expand the dataFields node to display Value, and click Filter Data.

       

     f.  Add a filter so that it only displays data when Key is equal to the text displayName.

       

     g. Click OK until all the dialogs are closed.
 
     h. Repeat Steps 1a to 1gfor the MyEmailAddress field, except that Value should be filtered such that Key is equal to the text mail.

       

Hint: To view a list of all the Active Directory keys, drag the whole ADProp node (/dfs:myFields/dfs:dataFields/tns:GetMyInfoResponse/tns:GetMyInfoResult/tns:ADProp) as a repeating table onto your form, and then preview.

 2.   Preview your form. Your Active Directory username and email address should be displayed in the My Info table.

  

Query GetManagerAlias

 1.  In the Controls task pane, click to add a button into the Manager Info table.

  

 2.  Double-click on the button to display its properties.
 
 3.  Label the button as Get Manager Info, and click Rules à Add à Add Action.

 4.  Add the following actions to query your manager’s alias using your alias which we obtained through GetMyInfo:

      a.  Set the field /dfs:myFields/dfs:queryFields/tns:GetManagerAlias/tns:username to the value of /dfs:myFields/dfs:dataFields/tns:GetMyInfoResponse/tns:GetMyInfoResult/tns:ADProp/tns:Value filtered such that Key is equal to sAMAccountName.
 
      b.  Query using the GetManagerAlias data connection.
 
Hint: If you wish to see the resulting value, temporarily drag /dfs:myFields/dfs:dataFields/tns:GetManagerAliasResponse/tns:GetManagerAliasResult into the view. When you preview your form and click the Get Manager Info button, you will see the manager’s alias display in the GetManagerAliasResult field. When done, you can now delete the GetManagerAlias field from the form’s view.

Query GetUserInfo

 1.  Double-click on the Get Manager Info button that we previously added, to go back to the button’s properties.
 
 2.  Add another rule with the following actions to obtain the manager’s name and email address:

     a.  Set the field /dfs:myFields/dfs:queryFields/tns:GetUserInfo/tns:username to the value of  /dfs:myFields/dfs:dataFields/tns:GetManagerAliasResponse/tns:GetManagerAliasResult

     b.  Query using the GetUserInfo data connection.

     c.   Set the ManagerName field /my:myFields/my:ManagerInfo/my:ManagerName to the value of /dfs:myFields/dfs:dataFields/tns:GetUserInfoResponse/tns:GetUserInfoResult/tns:ADProp/tns:Value filtered such that Key is equal to displayName.
 
    d.   Set the ManagerEmail field to the value of /dfs:myFields/dfs:dataFields/tns:GetUserInfoResponse/tns:GetUserInfoResult/tns:ADProp/tns:Value filtered such that Key is equal to mail.

       

 3.  Preview your form once again. Clicking the Get Manager Info button retrieves your manager’s name and email address.

    

Query GetEmployeesForManager

 1.   Add a button for the Employee Info table, and label it as Get Employee Info.
 
 2.   Add a rule to this button with the following actions to query a list of employees who have a manager with an alias obtained using GetManagerAlias.
 
     a.  Set the field /dfs:myFields/dfs:queryFields/tns:GetEmployeesForManager/tns:managerAlias to the value   of /dfs:myFields/dfs:dataFields/tns:GetManagerAliasResponse/tns:GetManagerAliasResult

     b.  Query using the GetEmployeesForManager

Hint: If you wish to see the resulting list of employees, temporarily drag /dfs:myFields/dfs:dataFields/tns:GetEmployeesForManagerResponse/tns:GetEmployeesForManagerResult/tns:entry as a repeating table into the view. When you preview your form and click the Get Employee Info button, you will see a list of employees who have the same manager as yours. When done, you can now delete the table from the form’s view.

 3.   Change the EmployeeName textbox into a drop-down list box.

   

 4.   Double-click on the EmployeeName drop-down to display its properties.
 
 5.   In the Data tab, under List box entries, select Look up values from an external data source, and choose GetEmployeesForManager from the Data source drop-down.
 
 6.  Click on the Select XPath button  for Entries, and expand the dataFields node to get to the entry repeating node.

   

 7.  Click on the Select XPath button for Display name, and select the display node. Your EmployeeName dropdown should be similar to this:

   

 8.  Click on the Rules button à Add à Add Action.

 9.  Here again, we will use the GetUserInfo method to retrieve the employee’s email address. Add the following actions:
 
     a.  Set the field /dfs:myFields/dfs:queryFields/tns:GetUserInfo/tns:username to the EmployeeName’s value (since it represents the queried employee’s alias).
 
     b.  Query using the GetUserInfo data connection.
 
     c.  Set the EmployeeEmail field to the value of /dfs:myFields/dfs:dataFields/tns:GetUserInfoResponse/tns:GetUserInfoResult/tns:ADProp/tns:Value filtered such that Key is equal to mail.

         

 10. Preview your form. First, you will have to click on the Get Manager Info button to retrieve the manager’s alias, and then click the Get Employee Info button to retrieve a list of employees in a drop-down, after which displays the email address of the selected employee.

   

Query IsUserMemberOfGroup

The IsUserMemberOfGroup method returns true if the user is part of the specified group, false otherwise.

To test this method in our sample form, follow these steps:

   1.  On the Data source task pane, select the IsUserMemberOfGroup secondary data source.

   

   2.  Expand the queryFields node to select tns:IsUserMemberOfGroup.

   

   3.  Drag this node as a Section with controls onto your form’s view.

   

   4.  Expand the dataFields node to get to the IsUserMemberOfGroupResult node.

   

   5.  Drag this node inside the IsUserMemberOfGroup section. By default, it uses a check box control to indicate if the query returns true or false.

     

   6.  Add a button with a rule that queries using the IsUserMemberOfGroup data connection.

   7.  Preview your form. Specify any value in the Username and Group Alias parameters. Clicking the button will result to either true (box checked) or false (box unchecked).

   

Query FindUsersByName

The FindUsersByName method attempts to find any users with a name matching the specified search string.  When searching for a user by name, you can select from the following search methods:

  • StartsWith
  • EndsWith
  • Contains
  • Exact

To test this method in our sample form, follow these steps:

 1.  On the Data source task pane, select the FindUsersByName secondary data source.

   

 2.  Expand the queryFields node to select tns:FindUsersByName.

   

 3.  Drag this node as a Section with controls onto your form’s view.

 4.  Expand the dataFields node to get to the entry repeating node.

   

 5.  Drag this node as a Repeating table inside the FindUsersByName section.

     

 6.  Add a button below the searchType drop-down, and double-click to see its properties.

 7.  Label the button as Find Users, then add a rule that queries using the FindUsersByName data connection.

 8.  Preview your form once again. Enter a value in the Name textbox and select any Search Type, and then click Find Users. The repeating table will populate with a list of names that match the specified parameters. The Value column shows the user’s alias, while the Display column shows the user’s display name.

   

Query FindUsersByAlias

FindUsersByAlias does the same thing as FindUsersByName, except that it performs the search through the user’s alias. Repeat all of the steps above, using the FindUsersByAlias’ nodes and parameters.

  

Query GetGroupsForUser

1.   Drag and drop button onto your canvas.

2.   Right click on the button and change the label (this tutorial uses GetGroupsForUser).

3.   Select Rules > Add… > Add Action… to add a new action.

4.   From the Action dropdown, select Query using a data connection, and select your GetGroupsForUser-v2.4 data connection. The action should look similar to the below screen.

   

5.   Click OK four times.

6.   Drag and drop queryFields (alias, and recursive), and dataFields(value, and display) from GetGroupsForUser secondary data source as a repeating table.

   

7.   Your final layout should look similar to the below layout.

   

8.   Preview the form.

   

9.   Enter a valid alias in the Alias text box, and click GetGroupsForUser button.

 Select Recursive checkbox, if you wish to get all the child groups of the parent group.

Query GetMembersofgroup

1.   Drag and drop a button onto your canvas.

2.   Right click on the button and change the label (this tutorial uses GetMembersOfGroup).

3.   Select Rules > Add… > Add Action… to add a new action.

4.   From the Action dropdown, select Query using a data connection, and select your GetMembersOfGroup-v2.4 data connection. The action should look similar to the below screen.

   

5.   Click OK four times.

6.   Drag and drop the queryFields (groupAlias, and maxCount), and the dataFields (value, and display) from GetMembersOfGroup secondary data source as a repeating table.

   

7.   Your final layout should look similar to the below layout.

   

8.   Preview the form.

   

9.   Enter a valid group alias, and max count value.

10. Click GetMembersOfGroup button.

Comments

 

Twitter Trackbacks for How to query the Active Directory Web Service - Aruna Akella [infopathdev.com] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 How to query the Active Directory Web Service - Aruna Akella         [infopathdev.com]        on Topsy.com

July 19, 2010 6:29 PM
Copyright © 2003-2012 Qdabra Software. All rights reserved.
View our Terms of Use.