Re: Getting Direct Reports (V2)
Hi @killerBee15 ,
I am no expert too, but I have tried and this was my result, the only limitation is that the number of levels down the structure depends on how many times you copy the part after // ****Start again**** I did not succeeded to do it in some form of a loop. Anyway it works, so mark my solution, if it is enough for you.
// First set of direct reports
Set(varResult, Office365Users.DirectReportsV2(TextInputCanvas2.Value));
ClearCollect(colAllTemp,varResult.value);
// Filter empty rows and first row
ClearCollect(colAll, Filter(colAllTemp, !IsBlank(accountEnabled)));
//Get results for first set of direct
ClearCollect(colAllTemp, ForAll(colAll,Office365Users.DirectReportsV2(ThisRecord.userPrincipalName)));
ClearCollect(colMergedResults, []); // define new empty collection
ForAll(colAllTemp,Collect(colMergedResults, ThisRecord.value) );
//Final collection
Collect(colAll,colMergedResults);
ClearCollect(colAllFinal, ForAll(Distinct(colAll, ThisRecord), Value)); // Set only uniqe values
ClearCollect(colAllFinalFiltered, Filter(colAllFinal, !IsBlank(accountEnabled)));
// ****Start again**** (third level)
ClearCollect(colAllTemp, ForAll(colAllFinalFiltered,Office365Users.DirectReportsV2(ThisRecord.userPrincipalName)));
Clear(colMergedResults);
ForAll(colAllTemp,Collect(colMergedResults, ThisRecord.value) );
//Final collection
Collect(colAll,colMergedResults);
ClearCollect(colAllFinal, ForAll(Distinct(colAll, ThisRecord), Value)); // Set only uniqe values
ClearCollect(colAllFinalFiltered, Filter(colAllFinal, !IsBlank(accountEnabled)));
// ****Start again**** (fourth level)
ClearCollect(colAllTemp, ForAll(colAllFinalFiltered,Office365Users.DirectReportsV2(ThisRecord.userPrincipalName)));
Clear(colMergedResults);
ForAll(colAllTemp,Collect(colMergedResults, ThisRecord.value) );
//Final collection
Collect(colAll,colMergedResults);
ClearCollect(colAllFinal, ForAll(Distinct(colAll, ThisRecord), Value));
This way I counted 1286 users in our org. 🙂
Regards,
Michal Páral