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