Option Explicit Public Function GetMappedFieldValue(ByVal objMappedFieldInfo, _ ByVal varRSValue, _ ByVal objCenApp) On Error Resume Next Const FIELD_NAME_END_DATE = "End_date" Const FIELD_END_DATE_FIND_VALUE = "12/31/2999" Const FIELD_END_DATE_REPLACE_VALUE = "" Const FIELD_NAME_AD_ENABLED = "AD_User_Status_Disabled" Const VAL_ENABLED = "0" Const VAL_DISABLED = "1" Dim varMappedValue varMappedValue = Null If objMappedFieldInfo.InternalFieldName = FIELD_NAME_END_DATE Then varMappedValue = varRSValue If varMappedValue = FIELD_END_DATE_FIND_VALUE Then varMappedValue = FIELD_END_DATE_REPLACE_VALUE End If GetMappedFieldValue = varMappedValue Exit Function ElseIf objMappedFieldInfo.InternalFieldName = FIELD_NAME_AD_ENABLED Then If varRSValue <> Empty Then if (varRSValue And 2) <> 0 Then varMappedValue = VAL_DISABLED Else varMappedValue = VAL_ENABLED End If Else varMappedValue = VAL_ENABLED End If GetMappedFieldValue = varMappedValue Exit Function End If If objMappedFieldInfo.ValueTableID > 0 Then varMappedValue = ConvertSingleChoiceVal(varRSValue, objCenApp, objMappedFieldInfo) Else 'If objMappedFieldInfo.ExternalFieldName = "CUSTNMBR" And objMappedFieldInfo.InternalFieldName = "great_plains_id" Then ' varMappedValue = RemovePrefix(varRSValue, "C0") 'Else varMappedValue = varRSValue 'End If End If LogMsg "GetMappedFieldValue: " & objMappedFieldInfo.InternalFieldName & "=" & varRSValue & "; " & varMappedValue GetMappedFieldValue = varMappedValue End Function Private Function ConvertSingleChoiceVal(ByVal varRSValue, _ ByVal objCenApp, _ ByVal objMappedFieldInfo) On Error Resume Next Dim objChoiceVal Dim lngCount Dim varKeys Dim lngChoiceVal Dim lngDSType Dim strTableName Dim strSQL Dim rsValTable Dim rsChoiceList Const cenDSEnsureOpenConnection = 1 Const cenUsers = 16 Const FLD_SRC_TBL_NAME = "tSourceTableName" Const FLD_DS_TYPE = "nDSType" Const FLD_ID = "nID" Const TBL_DTS_FLD_VAL_TBLS = "tblDtsFieldValueTables" If Not IsNull(varRSValue) Then lngChoiceVal = varRSValue If IsNumeric(varRSValue) Then 'assume if it's a number then it's a choice list value lngChoiceVal = CLng(varRSValue) Else If Len(CStr(varRSValue)) > 0 Then strSQL = "SELECT [" & FLD_SRC_TBL_NAME & "], [" & FLD_DS_TYPE & "] FROM [" & _ TBL_DTS_FLD_VAL_TBLS & "] WHERE [" & FLD_ID & "]=" & _ objMappedFieldInfo.ValueTableID Set rsValTable = objCenApp.DataStores(cenUsers).GetConnection(cenDSEnsureOpenConnection).Execute(strSQL) If Not rsValTable.EOF Then strTableName = rsValTable.Fields(FLD_SRC_TBL_NAME).Value lngDSType = CLng(rsValTable.Fields(FLD_DS_TYPE).Value) 'get the ID If objMappedFieldInfo.ExternalFieldName = "CUSTNMBR" And objMappedFieldInfo.InternalFieldName = "nCompanyName" Then strSQL = "SELECT [nID] FROM [" & strTableName & "] WHERE [great_plains_id]='" & _ Replace(CStr(varRSValue), "'", "''") & "'" Else strSQL = "SELECT [nID] FROM [" & strTableName & "] WHERE [tName]='" & _ Replace(CStr(varRSValue), "'", "''") & "'" End If Set rsChoiceList = objCenApp.DataStores.Item(CLng(lngDSType)).GetConnection(cenDSEnsureOpenConnection).Execute(strSQL) If Not rsChoiceList.EOF Then lngChoiceVal = rsChoiceList.Fields("nID").Value End If If Not rsChoiceList Is Nothing Then rsChoiceList.Close Set rsChoiceList = Nothing End If End If If Not rsValTable Is Nothing Then rsValTable.Close Set rsValTable = Nothing End If End If End If End If ConvertSingleChoiceVal = lngChoiceVal End Function Private Function RemovePrefix(ByVal varRSValue, ByVal strPrefix) On Error Resume Next Dim strValue Dim lngLen If Not IsNull(varRSValue) Then strValue = varRSValue lngLen = Len(strValue) strValue = MqStrMan_StripLeading(strValue, strPrefix) If Len(strValue) < lngLen Then 'we removed something 'remove any 0s lngLen = 0 Do While lngLen <> Len(strValue) lngLen = Len(strValue) strValue = MqStrMan_StripLeading(strValue, "0") Loop End If Else strValue = "" End If RemovePrefix = strValue End Function Private Function MqStrMan_StripLeading(ByVal strString, ByVal strRemoveString) On Error Resume Next Dim lngLength Dim strTempString strTempString = Trim(strString) If Len(strTempString) > 0 Then lngLength = Len(strRemoveString) If StrComp(strRemoveString, Left(strTempString, lngLength), vbTextCompare) = 0 Then strTempString = Right(strTempString, Len(strTempString) - lngLength) End If End If MqStrMan_StripLeading = strTempString End Function Private Sub LogMsg(strMsg) Dim moEventLogger Set moEventLogger = CreateObject("MqSysutils40.CMqEventLogger") moEventLogger.InitializeEventLogger If Not IsNull(strMsg) Then moEventLogger.LogEvent CStr(strMsg) End If End Sub