'**********************************************************
' cancelTrainings	'added by CC-000446
' @description: cancel distribute workflows
' @param: 
' @return: 
'**********************************************************
Function cancelTrainings
debug2File "Start cancelTrainings"
	For aW = 0 To wfvariables.recTrainees.Count-1		

		If wfvariables.recTrainees.Item(aW).Item("sDelete").value = "ja / yes" Then		
			'terminate the process
			AdminTerminateProcess wfvariables.recTrainees.Item(aW).Item("sProcessID").value
				
			'update the person objects
			'CC-000963
			sPersonComment = getObjectFields("fTrainingSurvey", "REGISTER", "rPerson", wfvariables.recTrainees.Item(aW).Item("ID").value, "sComment")	
			if sPersonComment = "" Then
				updateField "fTrainingSurvey", "REGISTER", "rPerson", wfvariables.recTrainees.Item(aW).Item("ID").value, "sComment", wfvariables.sCommentHistory.value
			end if
			updateField "fTrainingSurvey", "REGISTER", "rPerson", wfvariables.recTrainees.Item(aW).Item("ID").value, "sTrainingStatus", "1"
			updateField "fTrainingSurvey", "REGISTER", "rPerson", wfvariables.recTrainees.Item(aW).Item("ID").value, "sStatusInformation", "Nicht gelesen / Not read"
			
			Dim sCurrentUserGuid : sCurrentUserGuid = thisprocess.Creator
			'get the complete (firstname + lastname) username
			Dim sCurrentUserName : sCurrentUserName = wforganisation.GetOrgObjectById( sCurrentUserGuid ).GetAttributeValueByName("Vorname") & " " & wforganisation.GetOrgObjectById(sCurrentUserGuid).GetAttributeValueByName("Nachname")
			If Trim(sCurrentUserName) = "" Then 'use the LogIn Name if no complete name is defined
				sCurrentUserName = wforganisation.GetOrgObjectById( sCurrentUserGuid ).Name
			End If		
			sRowsAction = ""	'CC-000963
			sRowsAction = sRowsAction & "<Row>" &_
				"<Field internal_name='" & "m_date" & "'>" & convertToValidXML(Now) & "</Field>" &_
				"<Field internal_name='" & "m_user" & "'>" & convertToValidXML(sCurrentUserName) & "</Field>"	&_
				"<Field internal_name='" & "m_action" & "'>" & convertToValidXML(thisprocess.ProcessName) & "</Field>"	&_
				"<Field internal_name='" & "m_comment" & "'>" & convertToValidXML(wfvariables.sCommentHistory.value) & "</Field>"	&_
				"</Row>"	
			updateTableField "fTrainingSurvey", "REGISTER", "rPerson", wfvariables.recTrainees.Item(aW).Item("ID").value, "m_history", sRowsAction, False
						
		End If
	Next
debug2File "End cancelTrainings"
End Function