此处提供的转换脚本示例是处理“转换条目”屏幕中未决条目的一种最简单的情况。
OnTranslationEvent 处理程序会对资源中的第一个字符执行简单检查,并根据以下值执行操作:如果“a”转换条目设置为“忽略”,如果“b”转换条目被删除,则“c”将进行转换,否则将保持不变以进行手动转换。 请注意,整个代码中的计数器都可跟踪在脚本执行期间执行了哪些操作。 这对于调试或记录脚本每次运行时的执行情况非常有用,特别是对于自动脚本尤为有用。 很重要的一点是要牢记函数末尾的 Tools.Commit 命令,如果没有它,通过脚本所做的任何更改都将不会保存在数据库中。
调用的 TranslateResource() 函数只是检查系统中是否存在与通过未决转换条目传递给该函数的资源同名(包括 E2E 前缀)的资源。 如果不存在,脚本将添加该资源,然后执行转换。 如果已存在,则将创建从资源字符串到现有 CA Business Service Insight 资源的转换条目。
脚本的最终 Result 函数只是输出由该脚本执行的任务的相关说明。 代码如下所示:
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
| 版权所有 © 2012 CA。 保留所有权利。 | 就该主题发送电子邮件至 CA Technologies |