var retData = StructNew(); var newRecord = false; var dSame = true; // Data is the Same Flag var fSame = true; // Fields are the same Flag var ceObj = Server.CommonSpot.ObjectFactory.getObject("CustomElement"); var curSavedData = StructNew(); var fldsQry = QueryNew("temp"); var fldList = ''; var fldListLen = 0; var formID = ''; var dataPageID = 0; var i = 1; var x = 1; var fld = ''; var fldsAssocArray = StructNew(); var changedFieldDataArray = ArrayNew(1); var missingFieldsArray = ArrayNew(1); var fic_formid_fieldid = ""; var elementType = ''; var ceType = ''; var mFieldCompare = StructNew(); var mKey = ''; var elementInfo = StructNew(); // Get the dataPageID from the InputData structure if ( StructKeyExists(arguments.InputData, 'dataPageID') ) dataPageID = arguments.InputData.dataPageID; else if( StructKeyExists(arguments.InputData, 'savePageID') ) dataPageID = arguments.InputData.savePageID; else if ( StructKeyExists(arguments.InputData, 'PageID') ) dataPageID = arguments.InputData.pageid; // Get the FormID and ElementType from the InputData Struct elementInfo = preSaveFormElementInfo(InputData=arguments.InputData); // Set the FormID from the formID or the controlTypeID from the InputData Struct if ( structKeyExists(elementInfo,"formID") ) formID = elementInfo.formID; // Figure out the form/element type (and CEtype if applicable) so we know which CMD API lib to use to GetFields if ( structKeyExists(elementInfo,"elementType") ) elementType = elementInfo.elementType; if ( structKeyExists(elementInfo,"ceType") ) ceType = elementInfo.ceType; // - MOVED TO preSaveFormElementInfo() /* if ( StructKeyExists(arguments.InputData, 'formID') AND IsNumeric(arguments.InputData.formID) ) formID = arguments.InputData.formID; else if ( StructKeyExists(arguments.InputData, 'controlTypeID') AND IsNumeric(arguments.InputData.controlTypeID) ) formID = arguments.InputData.controlTypeID; */ // - MOVED TO preSaveFormElementInfo() /* if ( StructKeyExists(arguments.InputData,'Global') ) { elementType = "CustomElement"; // Custom Element if ( arguments.InputData.Global EQ 1 ) ceType = "global"; else ceType = "local"; } else if ( StructKeyExists(arguments.InputData,'formClass') AND arguments.InputData.formClass EQ 0 ) elementType = "SimpleFormElement"; // Simple Form else if ( !IsNumeric(formID) ) elementType = "MetadataForm"; // Custom Metadata // The 'else' goes with logic below for getting the ceObj -- but moved to preSaveFormElementInfo() else Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveFieldDataCompare: The Element Type could NOT be determined from submitted data!',arguments.InputData); */ // If we have an element type, otherwise log it if ( LEN(TRIM(elementType)) ) ceObj = Server.CommonSpot.ObjectFactory.getObject(elementType); // If custom metadata compare all data fields if ( elementType EQ "MetadataForm" ) { // Loop over all the FIC_ keys and find the fieldID and FormID, fieldname that match for ( mKey IN arguments.InputData ) { if ( LEFT(mKey,4) EQ "fic_" AND ListLen(mKey,"_") GTE 3 ) { // If this custom metdata input data then compare each field one at a time mFieldCompare = application.ADF.presaveform.preSaveFieldDataCompare(arguments.InputData,mKey); if ( !mFieldCompare.FieldsMatch ) { fSame = false; ArrayAppend(missingFieldsArray,mFieldCompare.FIELDNAME); } if ( !mFieldCompare.DataMatch ) { dSame = false; ArrayAppend(changedFieldDataArray,mFieldCompare.FIELDNAME); } } } } else { // Make sure we have a Valid FormID before going to all this work if ( IsNumeric(formID) AND formID GT 0 AND dataPageID GT 0 ) { // Get the current data for the element record curSavedData = application.ADF.ceData.getElementInfoByPageID(dataPageID, formID); if ( StructKeyExists(curSavedData,"values") ) { fldList = StructKeyList( curSavedData.values ); fldListLen = ListLen( fldList ); } // Get the field name for this element using the CMD API CustomElement object fldsQry = ceObj.GetFields( formID ); // build assoc array of fields keyed by fieldname for( x=1; x LTE fldsQry.recordCount; x=x+1 ) { fld = ReplaceNoCase( fldsQry.Name[x], 'FIC_', '', 'ALL' ); fldsAssocArray[fld] = fldsQry.ID[x]; } } // reset fld variable fld = ""; if ( IsNumeric(formID) AND formID GT 0 ) { // Loop over the fields in the Element for( i=1; i LTE fldListLen; i=i+1 ) { fld = ListGetAt(fldList, i); // Build the FIC field name fic_formid_fieldid = ""; if ( StructKeyExists(fldsAssocArray,fld) ) fic_formid_fieldid = 'FIC_#formID#_#fldsAssocArray[fld]#'; if ( LEN(TRIM(fic_formid_fieldid)) ) { if ( !StructKeyExists(arguments.InputData,fic_formid_fieldid) ) { fSame = false; dSame = false; ArrayAppend(missingFieldsArray,fld); } else { // check if the values exist if ( StructKeyExists( curSavedData.values, fld) AND StructKeyExists( arguments.InputData,fic_formid_fieldid) ) { if ( curSavedData.values[fld] NEQ arguments.InputData[fic_formid_fieldid]) { dSame = false; ArrayAppend(changedFieldDataArray,fld); } } } } else { retData.msg = "A valid field could not be determined from submitted data!"; // We didn't figure out the FIC Field Name, so log it! Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveDataCompare: #retData.msg#',arguments.InputData); break; } } } else { retData.msg = "A valid formID could not be determined from submitted data!"; // We didn't figure out the FormID and/or the FieldID, so log it! Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveDataCompare: #retData.msg#',arguments.InputData); } // For a NEW Record reset the data compare values if ( !IsNumeric(dataPageID) OR dataPageID LTE 0 ) { dSame = false; changedFieldDataArray = ArrayNew(1); newRecord = true; } } retData.formID = formID; retData.formType = elementType; retData.ceType = ceType; retData.ChangedDataFields = changedFieldDataArray; retData.MissingFields = MissingFieldsArray; retData.FieldsMatch = fSame; retData.DataMatch = dSame; retData.newRecord = newRecord; retData.dataPageID = dataPageID; return retData; var retData = StructNew(); var newRecord = false; var dSame = true; // Data is the Same Flag var fSame = true; // Fields are the same Flag var ceObj = ''; var inputFieldData = ""; var curSavedData = StructNew(); var curSavedFieldData = ""; var defaultFields = StructNew(); var formID = ''; var dataPageID = 0; var FieldName = ""; var FieldID = 0; var fic_formid_fieldid = ""; var missingFieldsArray = ArrayNew(1); var elementType = ''; var ceType = ''; var mKey = ''; var mFormID = ''; var mFieldID = ''; var mFieldName = ''; var mFIC_formid_fieldid = ''; var elementInfo = StructNew(); // Get the dataPageID from the InputData structure if ( StructKeyExists(arguments.InputData, 'dataPageID') ) dataPageID = arguments.InputData.dataPageID; else if ( StructKeyExists(arguments.InputData, 'PageID') ) dataPageID = arguments.InputData.pageid; // Get the FormID and ElementType from the InputData Struct elementInfo = preSaveFormElementInfo(InputData=arguments.InputData); // Set the FormID from the formID or the controlTypeID from the InputData Struct if ( structKeyExists(elementInfo,"formID") ) formID = elementInfo.formID; // Figure out the form/element type (and CEtype if applicable) so we know which CMD API lib to use to GetFields if ( structKeyExists(elementInfo,"elementType") ) elementType = elementInfo.elementType; if ( structKeyExists(elementInfo,"ceType") ) ceType = elementInfo.ceType; // - MOVED TO preSaveFormElementInfo() /* if ( StructKeyExists(arguments.InputData, 'formID') AND IsNumeric(arguments.InputData.formID) ) formID = arguments.InputData.formID; else if ( StructKeyExists(arguments.InputData, 'controlTypeID') AND IsNumeric(arguments.InputData.controlTypeID) ) formID = arguments.InputData.controlTypeID; */ // - MOVED TO preSaveFormElementInfo() /* if ( StructKeyExists(arguments.InputData,'Global') ) { elementType = "CustomElement"; // Custom Element if ( arguments.InputData.Global EQ 1 ) ceType = "global"; else ceType = "local"; } else if ( StructKeyExists(arguments.InputData,'formClass') AND arguments.InputData.formClass EQ 0 ) elementType = "SimpleFormElement"; // Simple Form else if ( !IsNumeric(formID) ) elementType = "MetadataForm"; // Custom Metadata // Did we figure out the form Type from the passed in data if ( LEN(TRIM(elementType)) EQ 0 ) Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveFieldDataCompare: The Element Type CAN NOT be determined from submitted data!',arguments.InputData); */ // If data if from a custom metadata form get formID and fieldID differently if ( elementType EQ "MetadataForm" ) { // Loop over all the FIC_ keys and find the fieldID and FormID, fieldname that match for ( mKey IN arguments.InputData ) { // Only use the "FIC_" keys if ( LEFT(mKey,4) EQ "fic_" AND ListLen(mKey,"_") GTE 3 ) { mFormID = ListGetAt(mKey,2,"_"); mFieldID = ListLast(mKey,"_"); mFieldName = application.ADF.fields.getCEFieldName(ceNameOrID=mFormID,FieldID=mFieldID); // If fieldNameOrID is a numeric assume we have a FieldID (and get the FieldName) // OR if fieldNameOrID is a string assume we have a FieldName (and get the FieldID) // and then loop over FIC keys to find a match for the FieldName if ( LEFT(arguments.fieldNameOrID,4) EQ "FIC_" AND ListLen(arguments.fieldNameOrID,"_") GTE 3 ) { mFIC_formid_fieldid = 'FIC_#mFormID#_#mFieldID#'; if ( arguments.fieldNameOrID EQ mFIC_formid_fieldid ) { FormID = mFormID; FieldID = mFieldID; FieldName = mFieldName; break; } } else if ( IsNumeric(arguments.fieldNameOrID) ) { if ( arguments.fieldNameOrID EQ mFieldID ) { FormID = mFormID; FieldID = mFieldID; FieldName = mFieldName; break; } } else { if ( arguments.fieldNameOrID EQ mFieldName ) { FormID = mFormID; FieldID = mFieldID; FieldName = mFieldName; break; } } } } } else { if ( LEFT(arguments.fieldNameOrID,4) EQ "fic_" AND ListLen(arguments.fieldNameOrID,"_") GTE 3 ) { FieldID = ListLast(arguments.fieldNameOrID,"_"); FieldName = application.ADF.fields.getCEFieldName(ceNameOrID=formID,FieldID=FieldID); } else if ( IsNumeric(arguments.fieldNameOrID) ) { FieldID = arguments.fieldNameOrID; FieldName = application.ADF.fields.getCEFieldName(ceNameOrID=formID,FieldID=FieldID); } else { FieldName = arguments.fieldNameOrID; FieldID = application.ADF.fields.getCEFieldId(ceNameOrID=formID,fieldName=FieldName); } } // Make sure we have a Valid FormID and FieldID before going to all this work if ( IsNumeric(formID) AND formID GT 0 AND FieldID GT 0 ) { // Build the FIC_FORMID_FIELDID key fic_formid_fieldid = 'FIC_#formID#_#FieldID#'; // Get the data from the inputData Struct if ( StructKeyExists(arguments.InputData, fic_formid_fieldid) ) inputFieldData = arguments.InputData[fic_formid_fieldid]; else { fSame = false; ArrayAppend(missingFieldsArray,fic_formid_fieldid); } if ( dataPageID GT 0 ) { // Get the current data for the element record curSavedData = application.ADF.ceData.getElementInfoByPageID(dataPageID, formID); if ( StructKeyExists(curSavedData,"values") AND StructKeyExists(curSavedData.values, FieldName) ) curSavedFieldData = curSavedData.values[fieldName]; else { fSame = false; ArrayAppend(missingFieldsArray,fieldName); } if ( elementType EQ "SimpleFormElement" ) newRecord = true; } else { // If we have an element type, otherwise log it if ( LEN(TRIM(elementType)) ) ceObj = Server.CommonSpot.ObjectFactory.getObject(elementType); else Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveFieldDataCompare: Form/Element Type CAN NOT be determinied from submitted data!',arguments.InputData); // Get the field name for this element using the CMD API CustomElement object fldsQry = ceObj.GetFields( formID ); if ( NOT StructKeyExists(fldsQry, FieldName) ) fSame = false; dSame = false; newRecord = true; } // Check if the values from the Save data and the input data are the same for this field if ( fSame EQ true AND inputFieldData EQ curSavedFieldData ) dSame = true; else dSame = false; } else { fSame = false; dSame = false; ArrayAppend(missingFieldsArray,arguments.fieldNameOrID); retData.msg = "A valid formID and/or FieldID could not be determined from submitted data!"; // We didn't figure out the FormID and/or the FieldID, so log it! Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveFieldDataCompare: #retData.msg#',arguments.InputData); } retData.formType = elementType; retData.MissingFields = missingFieldsArray; retData.FieldsMatch = fSame; retData.DataMatch = dSame; retData.newRecord = newRecord; retData.dataPageID = dataPageID; retData.formID = formID; retData.FieldID = FieldID; retData.FieldName = FieldName; retData.FieldValueSaved = curSavedFieldData; retData.FieldValueSubmitted = inputFieldData; return retData; var retData = StructNew(); retData.elementType = ''; retData.ceType = ''; retData.formID = ''; // Set the FormID from the formID or the controlTypeID from the InputData Struct if ( StructKeyExists(arguments.InputData, 'controlTypeID') AND IsNumeric(arguments.InputData.controlTypeID) AND arguments.InputData.controlTypeID NEQ 0 ) retData.formID = arguments.InputData.controlTypeID; else if (StructKeyExists(arguments.InputData, "controlID") AND IsNumeric(arguments.InputData.controlID) AND arguments.InputData.controlID NEQ 0 ) retData.formID = arguments.InputData.controlID; else if ( StructKeyExists(arguments.InputData, 'formID') AND IsNumeric(arguments.InputData.formID) AND arguments.InputData.formID NEQ 0 ) retData.formID = arguments.InputData.formID; // Figure out the form/element type so we know which CMD API lib to use to GetFields if ( StructKeyExists(arguments.InputData,'Global') ) { retData.elementType = "CustomElement"; // Custom Element if ( arguments.InputData.Global EQ 1 ) retData.ceType = "global"; // Global Custom Element else retData.ceType = "local"; // Local Custom Element } else if ( StructKeyExists(arguments.InputData,'formClass') AND arguments.InputData.formClass EQ 0 ) retData.elementType = "SimpleFormElement"; // Simple Form else if ( !IsNumeric(retData.formID) ) retData.elementType = "MetadataForm"; // Custom Metadata // If we have an element type, otherwise log it if ( LEN(TRIM(retData.elementType)) EQ 0 ) Application.ADF.log.addLogEntry('ADF.presaveform_1_0.preSaveFormElementInfo: The Element Type could NOT be determined from submitted data!',arguments.InputData); return retData;