【CQ需求实现】8. 使用按钮来克隆缺陷记录
1、在Recrod type的Action submit动作的Initialization中编写下面的脚本
Sub Defect_Initialization(actionname, actiontype)
' actionname As String
' actiontype As Long
' action is Submit
' record type name is Defect
rem This is record cloning code
Dim sessionObj
Dim entityDefObj
Dim nameList
Dim fieldName
Dim errString
Dim fieldType
Dim refList
Dim i
Dim entityDefName
Dim pID
' Declare the local constants. This script is long enough that I might do it in VB where I could have
' a different module contain these variables. BTW, There is a source file on the distribution clearquest.bas
' in the CQ installation directory that contains many of these declarations.
Const AD_SHORT_STRING = 1
Const AD_MULTILINE_STRING = 2
Const AD_INT = 3
Const AD_DATE_TIME = 4
Const AD_REFERENCE = 5
Const AD_REFERENCE_LIST = 6
Const AD_ATTACHMENT_LIST = 7
Const AD_ID = 8
Const AD_STATE = 9
Const AD_JOURNAL = 10
Const AD_DBID = 11
' The next two are in the next release of CQ, but go ahead and include them now
Const AD_QUESTIONMARK = 12
Const AD_STATETYPE = 13
' There isn't good error checking in VBScript so the liberal use of On Error is required
On Error resume next
set sessionObj = GetSession()
DebugWin("Submit_action_initialization::Beginning")
' This gets the type definition for the record type that you want to clone.
set entityDefObj = sessionObj.GetEntityDef(GetEntityDefName())
DebugWin("EntityDefName: " & GetEntityDefName())
rem If record was submitted via MakeChild push button, then get values of
rem fields that are in parent record
if ( sessionObj.NameValue("CloneParent") = 1 ) then
rem Get the parent record
entityDefName = GetEntityDefName
pID = sessionObj.NameValue( "ParentID" )
set ParentRec = sessionObj.GetEntity( entityDefName, pID)
DebugWin("CloneParent: " & sessionObj.NameValue("CloneParent"))
DebugWin("ParentID: " & pID)
' Enumerate the fields and add them to the cloned object
nameList = entityDefObj.GetFieldDefNames
For Each fieldName in nameList
DebugWin("Field Name: " & fieldName)
fieldType = entityDefObj.GetFieldDefType(fieldName)
' You have to do something special depending on the type
Select Case fieldType
Case AD_ID
Case AD_DBID
Case AD_STATE
Case AD_JOURNAL
Case AD_QUESTIONMARK
Case AD_STATETYPE
Case AD_ATTACHMENT_LIST
' Code here for dealing with attachments
Case AD_REFERENCE_LIST
DebugWin("AD_REFERENCE_LIST = " & fieldName)
Select Case fieldName
rem Ignore all these
Case "childrecords"
rem Process all these
Case Else
refList = ParentRec.GetFieldValue(fieldName).GetValueAsList
DebugWin("LBound: " & LBound(refList))
DebugWin("UBound: " & UBound(refList))
for i = LBound(refList) to UBound(refList)
' Add the value to the list
DebugWin("Reference List Value: " & refList(i))
call AddFieldValue(fieldName, refList(i))
Next
end Select
Case Else
' AD_SHORT_STRING, AD_MULTILINE_STRING, AD_INT, AD_DATE_TIME, AD_REFERENCE
' eliminate some fields that are internal to CQ and not really writable
' there should really be a call to discriminate these fields, maybe next release
Select Case fieldName
Case "is_active"
Case "version"
Case "lock_version"
Case "locked_by"
Case "is_duplicate"
Case "unduplicate_state"
Case Else
rem DebugWin("Setting value = " & ParentRec.GetFieldValue(fieldName).GetValue)
' Set the value of the cloned field to the same value it was in the current object
call SetFieldvalue(fieldName, ParentRec.GetFieldValue(fieldName).GetValue)
end Select
end Select
Next
rem Get the values of the fields in the parent record
pHeadline = "Clone of " & pID & ": " & GetFieldValue("Headline").GetValue
pDescription = ParentRec.GetFieldValue("Description").GetValue
rem Set the value of the fields in the child record
rem SetFieldValue "Headline", pHeadline
SetFieldValue "Add_description", pDescription
SetFieldValue "IsOriginal", "No"
SetFieldValue "RecordSet", pID
SetFieldValue "Headline", pHeadline
rem Blank out the fields that make this clone unique
SetFieldValue "BranchName", ""
rem Clear session variable
sessionObj.NameValue "CloneParent", 0
else
SetFieldValue "IsOriginal", "Yes"
SetFieldValue "RecordSet", GetFieldValue("id").GetValue
end if
DebugWin("Submit_action_initialization::Ending")
End Sub
2、在Recrod的Script的Basic中写入一个名叫cloneparent的函数
Function Defect_CloneParent(param)
' param As Variant
' record type name is Defect
set session = GetSession()
rem Set session variable to indicate record being submitted should
rem be clone/copy of parent
session.NameValue "CloneParent", 1
rem Set a session variable to store the parent id
session.NameValue "ParentID", GetFieldValue("id").GetValue
End Function
3、在Global scripts中创建一个DebugWin函数
' Subroutine that prints to the debug console (if up)
' some messages
Sub DebugWin(logMessage)
Dim sessionObj
set sessionObj = GetSession
sessionObj.OutputDebugString vbCrLf + "DEBUG: " + logMessage + vbCrLf
End Sub
4、Use a List View widget. Keep the ‘Add button and rename it. Delete the ‘New’ and ‘Remove’ buttons (if desired).
[ 本帖最后由 晓筱 于 2006-9-7 17:54 编辑 ]
附件
-
11111.gif
(17.23 KB)
-
2006-9-7 17:51
-
22222.gif
(8.82 KB)
-
2006-9-7 17:52
搜索更多相关主题的帖子:
克隆 按钮 缺陷 需求