I will start off by saying this issue only occurred once we upgraded from CRM SP1 Rollup 1 and was not an issue from CRM 2011 to CRM 2013 SP1.
The issue we are experience has to do with creating a new child record from a parent entity and a piece of JScript we have on the child entity form to switch the form based on the status reason. Whenever we switch the form, the attributes that were mapped from the parent entity to the child entity are cleared, as if we are creating a new record from the child entity rather than having created a record from the parent.
We have a piece of jscript that switches the form to a different form based on the status reason field. For example, lets say the status reasons for active status can be New or Released. The status on records defaults to New if creating a new record. Where if the status reason = New then switch to the 120 form, if the status reason = Released then switch to the 150 form. The code also has a check to see if we are already on the form we want to switch to do that we don't end up in an infinite loop. If we create a new record from the parent and the last form we were on in the child was the 150 form (i.e. the last record we were on in that entity was a Released record) the form switch gets evoked and switch back to the 120 form. When this occurs, all attributes that were mapped from the parent entity to the child entity get wiped out (the lookup to the parent is gone as well). If we close out of that window and try to "Add a New record" after the last form we were on was the 120 form, then the form switching code is not evoked and the attributes are mapped appropriately.
The JScript web resource resides on the child entity and the function is called "onLoad" event.
I have pasted an sample of the jscript below. The jscript is not our issue I believe as it works fine when it is not a new record and worked fine for all CRM 2011 updates an up through CRM 2013 SP1 but after SP1 Rollup 1 was applied it is no longer working. Tried to contact support and they have not been helpful.
////Routing Detail Form Switch
////Rev 1 20140205 NH
function switchForm() {
// variable to store the name of the form
var formlabel;
// get the option set value field
var statuscode = Xrm.Page.getAttribute("statuscode").getValue();
//switch statement to name the form for each option set value
switch (statuscode) {
case 861430000: //New
formlabel = "Routing Detail Default-120";
break;
case 861430005: // Released
formlabel = "Routing Detail Released-150";
break;
default: //
formlabel = "Routing Detail Default-120";
}
//check if the current form already, return if true (prevent infinite loop)
if (Xrm.Page.ui.formSelector.getCurrentItem().getLabel() == formlabel) {
return;
}
else {
var items = Xrm.Page.ui.formSelector.items.get();
for (var i in items) {
var item = items[i];
var itemId = item.getId();
var itemLabel = item.getLabel()
if (itemLabel == formlabel) {
//navigate to the form
item.navigate();
} //endif
} //end for
} //endelse
} //end function