The Translation script sample provided here is a fairly simplistic case of processing the Pending entries in the Translation Entries screen.
The OnTranslationEvent handler performs a simple check on the first character in the resource, and performs an action according to the value: If 'a' the translation entry is set to 'ignore', if 'b' it is deleted, 'c' it will be translated, or otherwise it is left unchanged to be manually translated. Note that the counters throughout the code keep track of what actions are performed during the script execution. This is very useful for debugging or documentation of the script executions each time it is run, especially when the script is automated. The Tools.Commit command at the end of the function is very important to remember, since without it none of the changes made by the script will be saved in the database.
The TranslateResource() function called, simply checks to see if a resource by the same name as the one passed to it by the pending translation entry (along with the E2E- prefix) exists in the system. If it does not, the script adds this resource and then performs the translation. If it already exists, then it creates a translation entry from the resource string to the existing CA Business Service Insight resource.
The final Result function of the script simply outputs a description of the tasks performed by the script. The code is as follows:
Option Explicit
dim translated
dim ignored
dim deleted
dim manually
dim ActionDate
Sub OnLoad()
'tools.log "Translation Script: In OnLoad procedure", "I"
End Sub
Sub OnTranslationEvent(entryDetails)
Dim dump
dump = entryDetails.Dump
tools.log dump
Dim resource, entryId
entryId = entryDetails.EntryId
resource = entryDetails.FieldValue(1)
ActionDate = entryDetails.LastActionDate
If mid(resource,1,1) = "a" Then
tools.IgnoreEntry entryId
ignored = ignored + 1
tools.log "ignored" & entryId & " " & resource
Else If mid(resource,1,1) = "b" Then
tools.DeleteEntry entryId
deleted = deleted + 1
tools.log "deleted" & entryId & " " & resource
Else If mid(resource,1,1) = "c" Then
TranslateResource resource, entryId
tools.log "translated" & entryId & " " & resource
Else
tools.SetManualTranslationEntry entryId, 1
manually = manually + 1
tools.log "manually" & entryId & " " & resource
End if
Tools.commit
End Sub
Sub TranslateResource(resource, entryId)
Dim newName
Dim vector
newName = "E2E-" & resource
if NOT tools.IsResourceExists(newName) Then
Dim resourceDetails
set resourceDetails = tools.GetResourceDetailsByDate(resource,ActionDate)
resourceDetails("ResourceName") = newName
resourceDetails("ResourceTypes") = "E2E Transactions"
tools.AddResourceByMap resourceDetails
end if
tools.TranslateEntry entryId, newName
End Sub
Sub Main()
end Sub
Function Result
Result = translated & "entries were translated, "& _
ignored & "entries were ignored," & _
deleted & "entries were deleted and "& _
manually & "entries were set to manually update!"
End Function
|
Copyright © 2013 CA.
All rights reserved.
|
|