'**********************************************************
' OpenDataDialog_MapToArchive
' @description: button function for opening a document, derived by OpenDocument_Default, but with an mapToArchive function included (added with CC-000370)
' @param: none
' @return nothing
'**********************************************************
Function OpenDataDialog_MapToArchive()
	If wfvariables.recStructure.iDocumentID.Value < 1 Then
		MsgBox getMessageText( "StandardWF", "CreateDocumentFirst", "Bitte erzeugen Sie zuerst das Dokument." ), vbInformation,"enaio"
		Exit Function
	End If

	OpenDataDialog_MapToArchive = -7
	'1) check if write access is granted, otherwise open the dialog in readonly mode
	Dim sObjectTypeId : sObjectTypeId = FindObjectType ( wfvariables.recStructure.iDocumentID.Value )
	
	'CC-000784
	If wfvariables.sDocumentNumber.value = "" Then
		sMsg = getMessageText ( "StandardWF", "HintNoMapToArchiveResetFunction", "Sie haben vermutlich Zurücksetzen im Kontextmenü geklickt. Daher werden keine Daten auf die Indexmaske übertragen.") 
		MsgBox sMsg, vbInformation, "enaio"
		application.OpenDataDlg wfvariables.recStructure.iDocumentID.Value, sObjectTypeId, 0  'readonly mode
		Exit Function
	End If	

	'added field length validation for CC-000644
	for a = 0 to wfvariables.Count - 1
		for b = 0 to wfvariables.recConfigWFFields.Count - 1
			if wfvariables.Item(a).Name = wfvariables.recConfigWFFields.Item(b).Item("sVariableName").Value then
				debug2file wfvariables.Item(a).Name & ": " & wfvariables.recConfigWFFields.Item(b).Item("iMaxLength").Value
				if CInt(wfvariables.recConfigWFFields.Item(b).Item("iMaxLength").Value) <> 0 Then
					If Len(wfvariables.Item(a).Value) > CInt(wfvariables.recConfigWFFields.Item(b).Item("iMaxLength").Value) Then
						sMsg = sMsg & getMessageText( "StandardWF", "FieldLengthStart", "Das Feld '") & getMaskFieldNameFromVariable (wfvariables.Item(a).Name) & getMessageText( "StandardWF", "FieldLengthEnd", "' überschreitet die maximale Feldlänge.") & " (" & wfvariables.recConfigWFFields.Item(b).Item("iMaxLength").Value & ")." & vbCrLf
					End If
				End If
			end if	
		Next
	Next
	if sMsg <> "" then 'show error message and don't forward the activity
		msgbox sMsg, vbInformation, "enaio"
		Exit Function
	end if	
	
	If sObjectTypeId <> "" Then
		iRet = application.CheckObjectAccess(wfvariables.recStructure.iDocumentID.Value, sObjectTypeId,1,1,0)
		If iRet = 1 Then
			dtrMapToArchive wfvariables.recStructure.iDocumentID.Value	'saves all wf variables to the document
			OpenDataDialog_MapToArchive = application.OpenDataDlg( wfvariables.recStructure.iDocumentID.Value, sObjectTypeId, 1 ) 'write mode
		Else
			OpenDataDialog_MapToArchive = application.OpenDataDlg( wfvariables.recStructure.iDocumentID.Value, sObjectTypeId, 0 ) 'readonly mode
		End If
	Else
		MsgBox getMessageText( "StandardWF", "OpenObjectError", "Das angeforderte Objekt kann nicht geöffnet werden." ), vbCritical, "enaio"
	End If
End Function