简体   繁体   中英

addCustomView in CRM 2013 lookup

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 suspect that the problem with be with the calls to SDK.REST as explained in this thread , but results in accountBU and relatedBusinessUnits are correct.

I have using another SDK call aith a correct behavior as:

 var systemUserTeam = SDK.REST.retrieveMultipleRecordsSync("TeamMembership",
                "$select=TeamId&$filter=TeamId eq guid'"
                + Xrm.Page.getAttribute("aux_owningteamid").getValue()[0].id
                + "' and SystemUserId eq guid'"
                + Xrm.Page.getAttribute("ownerid").getValue()[0].id
                + "'");
    if (systemUserTeam.results.length != 1) {

I'm setting up a Customer lookup view with custom fetchXML and laoyoutXML with same method except for the calls to SDK.

Which change could I do to the SDK call to get it working?

If you're not averse to rewriting the code there's now an easier and supported way of adding custom filters to a lookup. You could use an existing view and apply the preFilter.

This blog post provides a good example.

addCustomView doesn't work with Owner lookups. Owner lookups are used to assign user-owned records.

Link - https://msdn.microsoft.com/en-us/library/gg334266.aspx#BKMK_addCustomView

It is probably the object='1' in your layoutxml- objecttypecode of 1 means you are trying to create the view on account, when you need to create it on team. So CRM is making the custom view against account and they trying to call it against team. Team I believe is 9. That change should hopefully all else been right, have you sorted. If it isn't nine download and install the DynamicsXRMtools solution and check the CRM metadata.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM