This hook shows the code you can attach to a record script to clone a defect in ClearQuest. You can click on the button to create a copy of an existing defect. Here is the kind of script that you would use in CQ 1.1 to clone a defect by using a 'Record Script' and associating it with a button on your defect form. -------------------- Start of Hook ------------------------------------------------------- ' Declare all of your local variables. VBScript doesn't 'require this, but you can run into conflicts with CQ 'internal names if you don't. For technical reasons ' we implicitly declare local variables with the same names 'as the fields of your CR type which can overlap and cause a 'weird error if you don't 'Dim' them in your script. Dim sessionObj Dim entityDefObj Dim clonedObj Dim nameList Dim fieldName Dim errString Dim fieldType Dim refList Dim i ' 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 ' Session is the rock from which you can get the information about the other ' CQ records set sessionObj = GetSession ' This gets the type definition for the record type that you want to clone. set entityDefObj = sessionObj.GetEntityDef(GetEntityDefName()) ' Create the new defect set clonedObj = sessionObj.BuildEntity(GetEntityDefName()) ' Enumerate the fields and add them to the cloned object nameList = entityDefObj.GetFieldDefNames() For Each fieldName in nameList 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 refList = GetFieldValue(fieldName).GetValueAsList for i = LBound(reflist) to UBound(reflist) ' Add the value to the list call clonedObj.AddFieldValue(fieldName, refList(i)) Next 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 ' Set the value of the cloned field to the same value it was in the current object call clonedObj.SetFieldvalue(fieldName, GetFieldValue(fieldName).GetValue) end Select end Select Next errString = clonedObj.Validate if errString = "" then errString = clonedObj.Commit end if ' Return a string with what you want the system to report ' as a result of the button hook execution. This should work ' from the Web as well as the Windows GUI. if errString = "" then Defect_Clone = "Cloned Defect " & clonedObj.GetFieldValue("id").GetValue else Defect_Clone = errString end if -------------------- Start of Hook -------------------------------------------------------