We are migrating from CRM 2011 to CRM 2013, both on-premise version. We have a ribbon customization on the Case form using javascript that loads up a custom Lookup view of N:N associated Account entity. From this custom lookup view, users can associate the selected Account records with the current Case.
For some reason this function is not working anymore in crm 2013. The custom Lookup view is still loaded up correctly, however for some reason the Account records are not getting associated with the parent Case record anymore.
I read another question about this which was resolved using the link below by Paul Nieuwelaar: http://www.magnetismsolutions.co.nz/blog/paulnieuwelaar/2014/04/21/filter-n-n-add-existing-lookup-dynamics-crm-2013
Basically the ‘LookupObjects’ function is not working anymore in CRM 2013 and must be replace by ‘LookupObjectsWithCallback’.
However even after following this solution I'm still not able to associate the Account records to the Case. Here is my code below that I have modified to follow Paul Nieuwelaar's suggestion. Am I missing something here? I even included in the code if the CRM 2011 version is still using Rollup 12, just in case. I have a feeling this is probably because the parent Case was not picked up properly in the script.
Thanks, any help is greatly appreciated.
-elisabeth
function openAddLookupDialog(gridTypeCode) {
var relName = "new_account_incident";
var roleOrd = 2;
var viewId = "{00000000-0000-0000-00AA-000010001002}"; //dummy view ID
if (!IsNull(relName)) {
var customView = {
fetchXml: "{...}", //my FetchXML
id: viewId,
layoutXml: "{...}", //my layoutXml
name: "Filtered Lookup View",
recordType: gridTypeCode,
Type: 0
};
var parent = GetParentObject(null, 0);
var parameters = [gridTypeCode, "", relName, roleOrd, parent];
var callbackRef = Mscrm.Utilities.createCallbackFunctionObject("locAssocObjAction", this, parameters, false);
//pops the lookup window with our view injected
var lookupItems = LookupObjectsWithCallback(callbackRef, null, "multi", gridTypeCode, 0, null, "", null, null, null, null, null, null, viewId, [customView]);
}
if (lookupItems && lookupItems.items.length > 0) {
//beginning of rollup 12 must make modification
var parentId;
var parentTypeCode;
if (typeof (GetParentObject) == "function") { //post rollup 12 has its own function to get this
var parent = GetParentObject();
parentId = parent.id;
parentTypeCode = parent.objectTypeCode;
}
else { //pre rollup 12 still needs to use the old way
var parent = typeof (crmFormSubmit) == "undefined" ? $get("crmFormSubmit") : crmFormSubmit;
//according to daniels blog crmFormSubmit should already be defined, but it's not...
if (parent) {
parentId = parent.crmFormSubmitId.value;
parentTypeCode = parent.crmFormSubmitObjectType.value;
}
else {
parentId = window.parent.crmFormSubmit.crmFormSubmitId.value;
parentTypeCode = window.parent.crmFormSubmit.crmFormSubmitObjectType.value;
}
}//end of rollup 12 modification
//both of AssociateObjects that I try below here don't work
//AssociateObjects(crmFormSubmit.crmFormSubmitObjectType.value, crmFormSubmit.crmFormSubmitId.value, gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
AssociateObjects(parentTypeCode, parentId, gridTypeCode, lookupItems, IsNull(roleOrd) || roleOrd == 2, "", relName);
}
}
We also modified the customization.xml file to that triggers the javascript when the button is clicked.
<CommandDefinition Id="new.Form.incident.MainTab.Actions.AddExistingProperties.Command">
<EnableRules>
<EnableRule Id="new.Form.incident.MainTab.Actions.AddExistingProperties.Command.EnableRule.FormStateRule" />
<EnableRule Id="new.Form.incident.MainTab.Actions.AddExistingProperties.Command.EnableRule.ValueRule" />
</EnableRules>
<DisplayRules />
<Actions>
<JavaScriptFunction FunctionName="openAddLookupDialog" Library="$webresource:new_account_incident.js">
<IntParameter Value="1" />
</JavaScriptFunction>
</Actions>