Hi
I cant get my head around this error.
I'm trying to filter a subgrids "Add existing..."-button. The relationship is a N:N and my code looks like this:
function addExistingFromSubGridCustom(params) { var relName = params.gridControl.getParameter("relName"), roleOrd = params.gridControl.getParameter("roleOrd"), viewId = "{1DFB2B35-B07C-44D1-868D-258DEEAB88E2}"; // a dummy view ID var customView = { fetchXml: params.fetchXml, id: viewId, layoutXml: params.layoutXml, name: params.name, recordType: params.gridTypeCode, Type: 0 }; alert(relName); alert(roleOrd); alert(params.fetchXml); alert(params.layoutXml); alert(params.gridTypeCode); var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]); if (lookupItems && lookupItems.items.length > 0) { AssociateObjects(crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, params.gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName); } } function addExistingCustomFilter(gridTypeCode, gridControl, primaryEntityName) { // Here you can specify for which entity the filter should be applied. // For example, filter only when you try to add an existing record to a client. // In the other cases, you will call the default method. //var primaryEntityName2 = "client"; // if (primaryEntityName != "client") // { // Mscrm.GridRibbonActions.addExistingFromSubGridStandard(gridTypeCode, gridControl); // return; // } //Get a lookup value var lookupItem = new Array(); lookupItem = Xrm.Page.getAttribute("log_account").getValue(); if (lookupItem != null) { var guid = lookupItem[0].id; var name = lookupItem[0].name; } //Update the fetch that will be used by the grid. var fetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical">' + '<entity name="contact">' + '<attribute name="contactid" />' + '<attribute name="telephone2" />' + '</entity>' + '</fetch>'; // Add conditions to your fetch xml dynamically // Call the generic method with the rights arguments. addExistingFromSubGridCustom({ gridTypeCode: gridTypeCode, gridControl: gridControl, fetchXml: fetch, layoutXml: '<grid name="resultset" object='+gridTypeCode+' jump="telephone2" select="1" icon="1" preview="1">' + '<row name="result" id="contactid">' + '<cell name="telephone2" width="250"/>' + '</row>' + '</grid>', name: 'Custom Search View' }); }
The FetchXML here is just to try something more simpler then what I want, but even here it gives me an error
I also changed the XML on the button as I suppose to:
<CommandDefinition Id="Mscrm.AddExistingRecordFromSubGridAssociated"><EnableRules><EnableRule Id="Mscrm.AppendToPrimary" /><EnableRule Id="Mscrm.EntityFormIsEnabled" /></EnableRules><DisplayRules><DisplayRule Id="Mscrm.AddExisting" /><DisplayRule Id="Mscrm.ShowForManyToManyGrids" /><DisplayRule Id="Mscrm.AppendToPrimary" /><DisplayRule Id="Mscrm.AppendSelected" /><DisplayRule Id="Mscrm.CanWriteSelected" /></DisplayRules><Actions><JavaScriptFunction FunctionName="addExistingCustomFilter" Library="$webresource:log_filteredsubgrid"><CrmParameter Value="SelectedEntityTypeCode" /><CrmParameter Value="SelectedControl" /><CrmParameter Value="PrimaryEntityTypeName" /></JavaScriptFunction></Actions></CommandDefinition>
Can anyone help me with what the problem could be?
I'm getting the error when I push the button. First it gives me an "Error has occurred" pop up and after that a "Record is unavailable"-popup.
I have tried to debug the javascript, and the error is this line:
var lookupItems = LookupObjects(null, "multi", params.gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);