Hi,
I am quite new to Power Apps and learning on the go. I recently came across Direct reports (v2) using the Office365 property. I am able to get all the DirectReports of the given user. However, this does not satisfy my requirements. What I wanted is to do the following.
Imagine the organization chart are as follows:
A: Managing director
B: Technical director
C: product manager.
Here C reports to B and B reports to A. If I get the directReports of B I will get C. Similarly, If I get the direct reports of A I will get B. However, I want both B and C to be shown if I fetch the direct reports of A.
How can I achieve that using Power Apps?
Thanks in Advance!
Thank you for your response! I will try this and get back to you.
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
WarrenBelz
146,609
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
65,946
Most Valuable Professional