web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create a view for all ...
Power Apps
Answered

Create a view for all subordinates (direct+indirect reports)

(0) ShareShare
ReportReport
Posted on by 109

Hi,

I am trying to create a view for the users entity, which shows all manager's subordinates (direct and indirect reports up to 3-5 levels) to be used in the context of forms in Model-Driven apps.

 

can anyone help please.

 

Thanks,

Mohammad

 

  • caburk Profile Picture
    Microsoft Employee on at
  • mokhawaja Profile Picture
    109 on at

    hi @caburk ,

    thanks for your reply.

    may i did not mae my question clear!

    what I am trying to do is create lookup view which can be used in forms of other entities where the user can see and search and select only from all his/her subordinates, I read that documentation and went further and found an "Under" hierarchical operator but i should select an exact record with it while i want it to be "Under Current User".

    Check screenshot.

     

    thanks,

    Mohammad

    Capture.PNG
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    I have exactly the same problem.  Is this possible in a Model App?  I do not want to use a canvas app.

     

    Anyone got any ideas?

     

    Thanks,

     

     

    Lee

  • Verified answer
    mokhawaja Profile Picture
    109 on at

    Hi @Anonymous ,

    I was successful achieving this using fetchXML and JavaScript web resource that was attached to the onLoad event on a form.

    so here is the code used for it... all you need to do is change the "CONTROL_NAME" in the last line: (BUT KEEP THE DOUBLE QUOTES!)

     

    function newCustomLookupMethod(executionContext) {
     'use strict';
     var formContext = executionContext.getFormContext();
     var entityName = "systemuser";
     var viewDisplayName = "My Subordinates";
     var CurrentUserName = Xrm.Utility.getGlobalContext().userSettings.userName;
     var CurrentUserID = Xrm.Utility.getGlobalContext().userSettings.userId;
    
    
     //Dummy GUID for CustomLookupView.
     var viewId = '{19913985-f16b-4502-cff5-a9b172b108a2}';
    
     //Query to fetch filtered records.
     var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">'+
     '<entity name="systemuser">'+
     '<attribute name="fullname" />'+
     '<attribute name="businessunitid" />'+
     '<attribute name="title" />'+
     '<attribute name="address1_telephone1" />'+
     '<attribute name="positionid" />'+
     '<attribute name="systemuserid" />'+
     '<order attribute="fullname" descending="false" />'+
     '<filter type="and">'+
     '<condition attribute="systemuserid" operator="under" uiname="'+CurrentUserName+'" uitype="systemuser" value="'+CurrentUserID+'" />'+
     '<condition attribute="isdisabled" operator="eq" value="0" />'+
     '</filter>'+
     '</entity>'+
     '</fetch>';
    
     //Create layout for custom view.
     var layoutXml = '<grid name="resultset" object="8" jump="fullname" select="1" preview="0" icon="1" >' +
     '<row name="result" id="systemuserid" >' +
     '<cell name="fullname" width="200" />' +
     '<cell name="positionid" width="100" />' +
     '<cell name="address1_telephone1" width="100" />' +
     '<cell name="businessunitid" width="150" />' +
     '<cell name="siteid" width="150" />' +
     '<cell name="title" width="100" />' +
     '<cell name="internalemailaddress" width="200" />' +
     '<cell name="address1_fax" ishidden="1" width="100" />' +
     '</row>' +
     '</grid>';
     var isDefault = true;
    
     formContext.getControl("CONTROL_NAME").addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, isDefault);
    
    
    }

     

    and should you need more help with implementing it, just ping me and I'll help out step by step.

    I think it deserves a blog post!!!

     

    cheers for now

    Mohammad

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @malkhawaja,

     

    Excellent!  Works like a charm!  Thanks very much.

     

     


    Lee

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 382 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 329

#3
WarrenBelz Profile Picture

WarrenBelz 187 Most Valuable Professional

Last 30 days Overall leaderboard