Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Filter Account lookup to show Connected records

(0) ShareShare
ReportReport
Posted on by 1,875

Hi

I have two lookups both for Account entity. Lets call them Main and Connected. I want Connected lookup to be filtered and show only those accounts that are connected to Main lookup record with some specified role. Is that possible?

If yes, how?

*This post is locked for comments

  • Suggested answer
    RE: Filter Account lookup to show Connected records

    Hi,

    This might help if I got your question right,

    //fieldname :that you want it to be filtered
    //condition : can provide it from advanced find fetch xml
    
    function filterLookup()
    {
        if (CheckUserRole() == true) {
            Xrm.Page.getControl("Connected").addPreSearch(function () {
                var fetchXml = "<filter type='and'><condition/></filter>";
                Xrm.Page.getControl("Connected").addCustomFilter(fetchXml);
            });
        }
    }
    
    function CheckUserRole() {
        var currentUserRoles = Xrm.Page.context.getUserRoles();
        for (var i = 0; i < currentUserRoles.length; i++) {
            var userRoleId = currentUserRoles[i];
            var userRoleName = GetRoleName(userRoleId);
            if (userRoleName == "System Administrator") {
                return true;
            }
        }
        return false;
    }
    
    //Get Rolename based on RoleId
    function GetRoleName(roleId) {
        //var serverUrl = Xrm.Page.context.getServerUrl();
        var serverUrl = location.protocol + "//" + location.host + "/" + Xrm.Page.context.getOrgUniqueName();
        var odataSelect = serverUrl + "/XRMServices/2011/OrganizationData.svc" + "/" + "RoleSet?$filter=RoleId eq guid'" + roleId + "'";
        var roleName = null;
        $.ajax(
            {
                type: "GET",
                async: false,
                contentType: "application/json; charset=utf-8",
                datatype: "json",
                url: odataSelect,
                beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
                success: function (data, textStatus, XmlHttpRequest) {
                    roleName = data.d.results[0].Name;
                },
                error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + textStatus + errorThrown + odataSelect); }
            }
        );
        return roleName;
    }


    ref link for userrolecontrol : https://msdynamicscrmblog.wordpress.com/2013/03/10/get-login-user-role-names-in-javascript-in-dynamics-crm-2011/

    Hope it helps,

    Regards,

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: Filter Account lookup to show Connected records

    In that case you will have to write a javascript, you can get some ideas from following URLs:

    www.concurrency.com/.../filter-dynamics-crm-lookup-values-with-javascript

    www.inogic.com/.../apply-custom-filter-on-lookup-field-in-dynamic-crm-using-script

  • Deeps Profile Picture
    Deeps 1,875 on at
    RE: Filter Account lookup to show Connected records

    I am talking about Account connected using Connections feature.

  • PS Profile Picture
    PS 23,577 on at
    RE: Filter Account lookup to show Connected records

    Yes its possible.

    Go to the form editor of the entity where you have these lookups>>double click on connected lookup>>set the highlighted section shown below:

    7345.4.PNG

    save and publish.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,407 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans