if (!getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DoesRecordExist(FormRecord.ID))
{
g_IsNew = true;
g_NewRecord = FormRecord;
g_RecordID = FormRecord.ID;
}
else
g_RecordID = FormRecord.ID;
}
}
}
// Iterate through the form fields to properly set them up.
initSystemFields(FormRecord);
initFormElements(FormRecord);
// If the record is new and is a response, then set the _ParentID so that HasParentID property works
if (g_IsNew && g_IsResponse && g_SelectedID != -1)
FormRecord.SetField("_ParentID", g_SelectedID);
// Create an IGrooveFormsToolRecord global variable for scripters to use.
g_FormRecord = FormRecord;
Transaction.Commit();
}
catch (error)
{
//alert("Transaction aborted in initFormPage [" + error.description + "]");
Transaction.Abort();
}
// Make sure that the document is a valid response.
if (g_IsNew && g_IsResponse && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
{
getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The selected parent record has been deleted or is invalid. You will now be returned to the view.", "Invalid Selection");
// Check to see if this is a response record, and if it is valid to create.
if (g_IsResponse && !g_IsPreviewPane)
{
if (g_SelectedID == -1 || !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
ResponseError = true;
// MWATodo: update UI to add option for not allowing responses to a response.
/*
if (g_SelectedID != -1)
{
var SelectedFormURL = getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").DataDelegate.IGrooveFormsToolUserDataPrivate.OpenFormURLByRecordID(g_SelectedID);
var ElementValueArray = ElementValue.split(ElementValueSeparator);
for (var i = 0; i < ElementValueArray.length; i++)
{
for (var j = 0; j < i_Element.options.length; j++)
{
if (i_Element.options[j].value == ElementValueArray[i])
{
i_Element.options[j].selected = true;
break;
}
}
}
}
}
}
}
else
{
if (g_IsPreviewPane)
{
getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The record you have selected to preview has been deleted.", "Record Deleted");
location.replace("FormsBlankPage.html");
}
else if (!g_IsNew && !g_IsSearch && !g_IsFormPreview && !g_IsPrinting)
{
getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The record you have selected to edit has been deleted. You will be returned to the view.", "Record Deleted");
var OptionError = "There was an error adding the custom option to the drop-down list, most likely caused by the form reloading in response to a design change. Please try adding the custom option again.";
// Fire the onblur event for all elements in the form.
var DocumentForm = document.GrooveFormBase;
for (var i = 0; i < DocumentForm.elements.length; i++)
{
var DocumentElement = DocumentForm.elements[i];
if (DocumentElement.getAttribute("DATATYPE") == "RichText")
validateRequired(DocumentElement);
else
DocumentElement.fireEvent("onblur");
}
// Validate that all required contact fields have a contact.
var DocumentSpans = document.getElementsByTagName("SPAN");
for (var i = 0; i < DocumentSpans.length; i++)
{
if (DocumentSpans[i].getAttribute("DATATYPE") == "Contact")
validateRequired(DocumentSpans[i]);
}
g_BypassEventCallouts = false;
// Check error array to see if there are still uncorrected errors.
for (var i = 0; i < g_arrErrors.length; i++)
{
if (typeof g_arrErrors[i] != "undefined")
{
getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("The form values you have entered are not valid. Please correct the error(s) as displayed in the form.", "Invalid Form Values");
if (g_IsNew && g_IsResponse && !g_SaveAsMain && !getScriptHostQI("IGrooveFormsToolUIDelegatePrivate").IsValidRecord(g_SelectedID))
{
getScriptHostQI("IGrooveFormsToolUIDelegate").DisplayOKMessageBox("You cannot save this record because it is a response to a record that has been deleted. If you want to save data from this record, you can copy and paste it (for example, to Notepad) before closing the record.", "Invalid Selection");
return;
}
var Transaction = getScriptHostQI("IGrooveFormsToolUIDelegate").OpenTransaction();
try
{
var FormRecord;
if (!g_IsSearch)
{
FormRecord = openCurrentRecord();
if (FormRecord != null)
{
// If the record is versioned, save a copy as a child.
displayStatusBar("The field '" + KeyValue + "' does not exist on the form, so the lookup for the field '" + FieldName + "' was not performed.", GrooveMessageBoxIcon_Error);