加入收藏 | 设为首页 | Life家族 | SCMLife | RMLife | PMLife | SQALife | TESTLife | 企业VIP专区 | 中文化荣誉殿堂
 
发新话题
打印

[推荐] 【CQ需求实现】8. 使用按钮来克隆缺陷记录( 此文章被查看:4758次,被回复:4篇!! )

【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

11111.gif

22222.gif (8.82 KB)

2006-9-7 17:52

22222.gif




© 本文为 晓筱SCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

LZ :
有個疑問,record type中的action submit動作 initalization的腳本,是怎麼被觸發的

click "cloneparent"這個按鈕,就可以觸發發嗎,我試了下,似乎沒有調用initalization.


請指教下!!
謝謝!!



© 本文为 yingSCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

请问有perl实现的代码吗?



© 本文为 自在飞SCMLife 共同所有,未经同意,请勿转载 ©如该文侵犯了您的版权,请联系管理员

TOP

lz提供的好东西,下载学习!!

© 本文为 ty1227 所有,未经同意,请勿转载
©如该文侵犯了您的版权,请联系管理员

TOP

不怕见笑,我第一次关注这个克隆(应该也叫继承吧)这个功能,了解的同仁能不能给我解释一下克隆的功能
能实现什么操作啊?
看着楼主处理界面很厉害 但偶不知道有何用意  再次请教
CQ研究还不是很深,还劳烦大家耐心告知  谢谢

© 本文为 tongfenglcz 所有,未经同意,请勿转载
©如该文侵犯了您的版权,请联系管理员

TOP

发新话题