locked
addCustomView in CRM 2013 lookup RRS feed

  • Question

  • I get an Savedquery With Id = 00000000-0000-0000-0000-000000000000 Does Not Exist message when I set up the custom view to a CRM 2013 Team lookup, whit this code, working in CRM 2011.

    // Set the Owning Team View based on the account selected
    function setOwningTeamView(entityFieldName, lookupFieldName, resetSelection) {
      // Get the selected entity 
      var account = Xrm.Page.getAttribute(entityFieldName).getValue();
    
    if (account != null) {
        var accid = account[0].id;
        var accname = account[0].name;
    
        if (resetSelection == true) {
            // reset old selection for Contact
            Xrm.Page.getAttribute(lookupFieldName).setValue(null);
        }
    
        // use randomly generated GUID Id for the view
        var viewId = "{0CBC820C-7033-4AFF-9CE8-FB610464DBD3}";
        var entityName = "team";
    
        // give the custom view a name
        var viewDisplayName = "Teams applicable to " + accname + "";
    
        var accountBU = SDK.REST.retrieveRecordSync(Xrm.Page.getAttribute("a_account").getValue()[0].id, "Account", "OwningBusinessUnit", "");
        var relatedBusinessUnits = SDK.REST.retrieveMultipleRecordsSync("BusinessUnit", "?$select=BusinessUnitId,Name&$filter=a_Type/Value eq 1");
        var FetchXMLBU = "";
        for (var i = 0; i < relatedBusinessUnits.results.length; i++) {
            FetchXMLBU += "<value>" + relatedBusinessUnits.results[i].BusinessUnitId + "</value>"
        }
    
        debugger;
    
        // find all contacts where parent customer is the account selected and where the Contact record is active
        var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"
            + "<entity name='team'>"
            + "<attribute name='teamid' />"
            + "<attribute name='name' />"
            + "<attribute name='description' />"
            + "<attribute name='businessunitid' />"
            + "<filter>"
            + "<condition attribute='businessunitid' operator='in'>"
            + "<value>" + accountBU.OwningBusinessUnit.Id + "</value>"
            + FetchXMLBU
            + "</condition>"
            + "</filter>"
            + "</entity>"
            + "</fetch>";
    
        // build Grid Layout
        var layoutXml = "<grid name='resultset' " +
            "object='1' " +
            "jump='teamid' " +
            "select='1' " +
            "icon='0' " +
            "preview='0'>" +
            "<row name='result' id='teamid'>" +
            "<cell name='name' width='200' />" +
            "<cell name='businessunitid' width='200' />" +
            "<cell name='description' width='400' />" +
            "</row>" +
            "</grid>";
    
        // add the Custom View to the indicated [lookupFieldName] Control
        Xrm.Page.getControl(lookupFieldName).addCustomView(viewId, entityName, viewDisplayName, fetchXml, layoutXml, true);
        //The following line is the an unsupported way of disabling the View Picker, currently there is no supported way.
        document.getElementById(lookupFieldName + "_i").setAttribute("disableViewPicker", "1");
        //document.getElementById(lookupFieldName).setAttribute("disableViewPicker", "1");
    }
    }

    I'm also setting up a Customer lookup view with addCustomView with same code except for the calls to SDK and works well.

    This is the fetchXMl generated:

    "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='team'><attribute name='teamid' /> <attribute name='name' /> <attribute name='description' /> <attribute name='businessunitid' /> <filter> <condition attribute='businessunitid' operator='in'>

    <value>d2f2af7c-9c2e-e411-a53a-00155d5248a4</value><value>cff2af7c-9c2e-e411-a53a-00155d5248a4</value><value>d0f2af7c-9c2e-e411-a53a-00155d5248a4</value> </condition></filter></entity></fetch>"


    What can I change here to get this working?


    • Edited by RDevelopment Wednesday, September 3, 2014 3:56 PM
    Wednesday, September 3, 2014 3:38 PM

All replies

  • Jorge,

    I hope this can help you:

    var layoutXml = "<grid name='resultset' " + "object='9' " + "jump='teamid' " + "select='1' " + "icon='0' " + "preview='0'>" + "<row name='result' id='teamid'>" + "<cell name='name' width='200' />" + "<cell name='businessunitid' width='200' />" + "<cell name='description' width='400' />" + "</row>" + "</grid>";

    Change to:

    var layoutXml = "<grid name='resultset' " +
            "object='9' " +
            "jump='teamid' " +
            "select='1' " +
            "icon='0' " +
            "preview='0'>" +
            "<row name='result' id='teamid'>" +
            "<cell name='name' width='200' />" +
            "<cell name='businessunitid' width='200' />" +
            "<cell name='description' width='400' />" +
            "</row>" +
            "</grid>";

    Monday, November 17, 2014 9:48 AM
  • Thanks for your reply Aileen, but tried that and still getting same error.
    Tuesday, November 18, 2014 9:37 AM