cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
malkhawaja
Advocate II
Advocate II

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

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
caburk
Power Apps
Power Apps

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

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

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

@malkhawaja,

 

Excellent!  Works like a charm!  Thanks very much.

 

 


Lee

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Kudoed Authors
Users online (24,468)