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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

filter lookup using javascript

(0) ShareShare
ReportReport
Posted on by

hi all

i created filter lookup using javascript in crm 2013 but am getting errors

/ FUNCTION: FilterCDA
function FilterCDA(patientFieldName, lookupFieldName) {
 
    var isPatient = window.parent.opener.Xrm.Page.getAttribute("ccx_expectedaudience").getValue();
 
    if (isPatient == 803080000) {
        setLookup(patientFieldName, lookupFieldName);
    }
 
}
 
// FUNCTION: setLookup
function setLookup(patientFieldName, lookupFieldName) {
 
    // Get the selected Account Id in the [patientFieldName] indicated control
    //    var patientId = window.parent.opener.Xrm.Page.getAttribute(patientFieldName).getValue()[0].id;
    var patient = window.parent.opener.Xrm.Page.getAttribute(patientFieldName).getValue();
    if (patient != null) {
        var patientId = patient[0].id;
        var patientName = patient[0].name;
 
        // use randomly generated GUID Id for our new view
        defaultViewId = Xrm.Page.getControl(lookupFieldName).getDefaultView();
        //        var viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}";
        var entityName = "ccx_clientcaredoc";
 
        // give the custom view a name
        var viewDisplayName = "Related CDAs for " + patientName + "";
 
        var fetchXml = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">' +
            "<entity name='ccx_clientcaredoc'>" +
            "<attribute name='ccx_clientcaredocid'/>" +
            "<attribute name='ccx_name'/>" +
            '<attribute name="createdon"/>' +
            "<order attribute='ccx_name' descending='false'/> "+
            "<filter type='and'>" +
            "<condition attribute= 'ccx_client' operator='eq' value='[{7bfd140aaf-4df4-11dd-bd17-0019b9312238}]' /> "+
            "</entity>" +
            "</fetch>";
 
        // build Grid Layout
        var layoutXml = "<grid name='resultset' " +
            "object='1' " +
            "jump='ccx_clientcaredocid' " +
            "select='1' " +
            "icon='1' " +
            "preview='1'>" +
            "<row name='result' " +
            "id='ccx_clientcaredocid'>" +
            "<cell name='ccx_name' " +
            "width='250' />" +
            "</row>" +
            "</grid>";
 
        // add the Custom View to the indicated [lookupFieldName] Control
        Xrm.Page.getControl(lookupFieldName).addCustomView(defaultViewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
    }
 
 
    else {
        // no Account selected, reset Contact Lookup View to the default view such that all Contacts are displayed for selection
        Xrm.Page.getControl(lookupFieldName).setDefaultView(defaultViewId);
    }
 
}
please provide some suggestion 
 

*This post is locked for comments

I have the same question (0)
  • Aileen Gusni Profile Picture
    44,524 on at

    Hi,

    What error you encounter?

  • Hosk Profile Picture
    on at

    what errors are you getting?

    is the code compiling and then throwing an error whilst running?

    start simple and step through the code using the javascript debugger (PRESS F12)

  • Arpita Saini Profile Picture
    Microsoft Employee on at

    What is the update rollup in CRM. There are multiple issue fixed on lookup in UR3  and SP1 UR1.

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Katik,

    I don't know whether it is a typo or not when you type to this forum.

    In this line:

    / FUNCTION: FilterCDA

    If your purpose was to comment, then you should change

    // FUNCTION: FilterCDA

    Thanks.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans