cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
malkhawaja
Level: Powered On

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

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
malkhawaja
Level: Powered On

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

Hi @LeeDolbyNTT ,

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

 

View solution in original post

5 REPLIES 5
Power Apps Staff caburk
Power Apps Staff

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

Highlighted
malkhawaja
Level: Powered On

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

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

LeeDolbyNTT
Level: Powered On

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

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

malkhawaja
Level: Powered On

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

Hi @LeeDolbyNTT ,

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

 

View solution in original post

LeeDolbyNTT
Level: Powered On

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

@malkhawaja,

 

Excellent!  Works like a charm!  Thanks very much.

 

 


Lee

Helpful resources

Announcements
thirdimage

Power Apps Super User Class of 2020

Check it out!

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

SecondImage

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Top Kudoed Authors (Last 30 Days)
Users online (4,995)