I have the following function used to log changes to my form fields. If I call this function from my ajax return which looks up the manager’s name, I am having a problem where the log fields are not being updated before the form submits. If I use the alerts for the History_Events field, they show the change (first alert does not have the new value, it is written, and the second alert has the new value), but when looking at the field on the form after the onSubmit completes, the change is not in the form.
If I place an alert in the onSubmit (stopping the execution of the onSubmit until I click the button), the update gets written to the form. I have also placed a timer in this event right before the submit actually happens, but the field is still not showing as updated. Only something that interrupts the submittal (the alert) allows the field change to be posted with the document.
The call to the log from the ajax return handler is below and I have confirmed that it works and that the log process the information correctly:
//mgrname[1] open
//mgrname[2] sub
//mgrname[3] field
//indexes are for old, new, field name
j = logDocChanges(isNewDoc, mgrname); //log the document changes
return true;
function logDocChanges(isNewDoc, retValue){
//retValue may be either an array passed from the ajax return or null if passed directly from the onSubmit event
//retValue indexes are for old 1, new 2, field name 3
var currDate = new Date();
var logTime = getCurrDate(currDate);
if(isNewDoc == "True"){
//just log directly to the fields
frm.History_Date.value = logTime + ";;";
frm.History_User.value = g_username + ";;";
frm.History_Events.value = "Document created." + ";;";
return true;
}
var logArray = new Array;
var logArrayCounter = 0;
for (var b in submitValues){
if (submitValues[b] != openValues[b]){
//if b is the Approver field and the 7 Leftmost characters of either value are MANAGER, get the manager's names based on the
//lookup value and log them instead of the field value else log the field value.
if (b == "Approver"){
//need to build the check variables from open and submit, then do the check because one or both of these may
//be an array or they may not be.
if (Left(submitValues[b], 7) == "MANAGER" || Left(openValues[b], 7) == "MANAGER"){
//use the values in the temp array variable if they are not blank. Else, use submitvalue variables
//retValue indexes are for new 1, old 2, field name 3
if (isArray(retValue)){
if (retValue[1] == ""){
retValue[1] = openValues[b];
}
if (retValue[2] == ""){
retValue[2] = submittedValues[b];
}
}else{
retValue[1] = openValues[b];
retValue[2] = submittedValues[b];
}
logArray[logArrayCounter] = b + " (former: '" + retValue[1].toUpperCase() + "' new: '" + retValue[2].toUpperCase() + "');";
logArrayCounter++
}else{
logArray[logArrayCounter] = b + " (former: '" + openValues[b] + "' new: '" + submitValues[b] + "');";
logArrayCounter++
}
}else{
//just log the old value if it is not "Approver"
logArray[logArrayCounter] = b + " (former: '" + openValues[b] + "');";
logArrayCounter++
}
}
}
//window.alert("got this far");
if (logArray.length > 0){
frm.History_Date.value = frm.History_Date.value + ";;";
frm.History_User.value = frm.History_User.value + ";;";
frm.History_Events.value = frm.History_Events.value + ";";
}
//Append this array to frm.History_Events.value
//window.alert(frm.History_Events.value);
for (var e = 0; e < logArray.length; e++){
//append each entry to the field
frm.History_Events.value += logArray[e];
}
frm.History_Events.value += ";"
//window.alert(frm.History_Events.value); //the form is getting submitted before the value is actually written to the form!!!!
//append logArray.length -1 # of asterisk rows to the History_Date and History_User fields if there is more than one entry in logArray
var asterisks = "";
if(logArray.length > 1){
for (var a = 1; a < logArray.length; a++){
asterisks = asterisks + "*;";
}
}
//Build the History_Date and History_User fields
frm.History_Date.value = frm.History_Date.value + ";" + logTime + ";;" + asterisks + ";;";
frm.History_User.value = frm.History_User.value + ";" + g_username + ";;" + asterisks + ";;";
//recycle all objects here Disable for testing if not submitting the form.
logArray = null;
submitValues = null;
openValues = null;
return true;
}