Thanks for your reply. You are mostly correct, but I already have a function that calls onSave to delay the execution of sendAnswers(). What actually calls onSave is this:
function waitForSave() {
var formType = parent.Xrm.Page.ui.getFormType();
if (formType === 1) {
setTimeout(getAnswers, 2000);
}
else if (formType === 2) {
setTimeout(getUpdateOrChanged, 1500);
}
}
The function you see here -- getAnswers -- retrieves the data stored in a hidden field on the registration form, and then calls sendAnswers to actually create the records:
function getAnswers() {
var guid = Xrm.Page.data.entity.getId();
var regId = guid.slice(1, -1);
var jsonAnswer = parent.Xrm.Page.getAttribute("new_hiddenanswers").getValue();
if (jsonAnswer != null) {
console.log("first save for this event");
var parsedAnswer = window.JSON.parse(jsonAnswer);
var count = parsedAnswer.length;
for (var i=0; i<count; i++){
parsedAnswer[i].new_AssociatedRegId = {Id: regId, LogicalName: "new_registration"};
}
sendAnswers(parsedAnswer);
}
else if (jsonAnswer === null) {
console.log("no answers");
return;
}
}
To be clear -- when I say it fails on the first try, I mean only the VERY first try fails. So, I log on, test, and it fails. After that, I can open up a totally new registration and it'll work correctly all the way through. Any ideas?