How To

Group OUs into a Single DataSet

By Default the Active Directory connector can access one OU at a time. As Data Sync can be extended with custom code you can collate all of your organisational units (OUs) into one dataset using Dynamic Columns.

If you want to read multiple OUs then you can override the Data Load with Dynamic Columns and call the underlying load multiple times. This is slightly tricky with data connectors that use identifier columns but can be done like the example below.

Within Dynamic Columns add this method below to override the Data Load and call it twice with the different OU Path. This has the effect of combining the 2 data sets. Note that this will only work if your reading from AD i.e. AD is your source.

 public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader) 
    {
        var myreader = GetDataSourceA();
    
        myreader.LDAPPath = "LDAP://OU=TestUsers,DC=internal,DC=simego,DC=com";    
        dt = myreader.GetDataTable(dt);
        
        myreader.LDAPPath = "LDAP://OU=CRM2016,DC=internal,DC=simego,DC=com";    
        
        foreach(DataTableStoreRow row in reader.GetDataTable(reader.SchemaMap.GetDataTable()).Rows)
        {
            dt.Rows.AddWithIdentifier(row, row.ItemIdentifierData);
        }
            
        return dt;                    
    }

Here is an alternative answer where we use an array of OUs and loop round them. The first one needs to called slightly differently after that you can easily loop the others.

public override DataTableStore GetDataTable(DataTableStore dt, IDataSourceReader reader) 
{
	var myreader = GetDataSourceA();

	myreader.LDAPPath = "LDAP://OU=TestUsers,DC=internal,DC=simego,DC=com";	
	dt = myreader.GetDataTable(dt);
	
	var myOUs = new [] { 
		"LDAP://OU=CRM2016,DC=internal,DC=simego,DC=com", 
		"LDAP://OU=CRM2015,DC=internal,DC=simego,DC=com"
	};
	
	foreach(var ou in myOUs)
	{
		 myreader.LDAPPath = ou;    
    
        foreach(DataTableStoreRow row in reader.GetDataTable(reader.SchemaMap.GetDataTable()).Rows)
        {
            dt.Rows.AddWithIdentifier(row, row.ItemIdentifierData);
        }	
	}
	
	return dt;
				
}