August 3, 2007
Set Custom Field To Defect Number
The following article illustrates how to use the TestTrack Integration, along with custom fields and triggers, and be able to easily identify the defect number that files are attached to. Surround SCM already provides ways to filter and use the defect number that a file is attached to. This article simply extends this functionality to display the defect number in the source file list pane in the Surround SCM client. This is for display purposes only. [toc]
Works with Surround SCM 5 and later
RequirementsThe only requirement for this is that Surround SCM is set up to integrate with TestTrack Pro. Also, custom fields were introduced in version 5 of Surround SCM, so you must have at least version 5.0 installed.
Custom FieldsFirst, we must create a custom field that we will use to display the defect number. The main advantage of this is that now we can take advantage of the functionality of custom fields, like displaying them in the file pane, restrict when another trigger may be fired, etc. The Surround SCM User Guide includes more information about custom fields.
Setting Up the Custom FieldTo create a custom field in Surround SCM choose Tools > Administration > "Custom Fields.
- Field name: Should be something meaningful. Use something to match the terminology already in use in your environment.
- Field code: Should be unique and resemble the field name for easy identification. This field code can be used as an environment variable in scripts or email templates.
- Field format: Select the type of custom field. I chose it to be an integer for sorting reasons. Making it a string may not result in the desired sorting.
- Field Properties: I have left this blank.
Displaying the Custom Field in the Source File List PaneTo display any custom field in the Source File List pane, place your mouse cursor over any of the columns, right click, select Custom Fields><Name of your custom Field> as shown in Figure 4:
The Script FileThe next step is to create the script. Create the script before creating the trigger, because you will have to reference the script in the trigger. How can you reference something that does not exist yet? For this example I am in a windows environment and will be using batch files.
Creating the Script FileFollowing is the syntax for the SetCustomField CLI command:
- sscm setcustomfield FileName FieldID Value [-bBranch] [-pRepository] [-h] [-y[Username:Password|+]] [-zSCMServerAddr:PortNum] [+u]
- sscm scf "%SSCM_FILE%" 1007 %SSCM_DEFECTNUMBER% -b"%SSCM_BRANCH%" -p"%SSCM_REPOSITORY%" -yAdministrator: -z127.0.0.1:4900
- echo sscm scf %SSCM_FILE% 1007 %SSCM_DEFECTNUMBER% -b"%SSCM_BRANCH%" -p"%SSCM_REPOSITORY%" -yAdministrator: -z127.0.0.1:4900 >D:test.log
- sscm scf "%SSCM_FILE%" 1007 %SSCM_DEFECTNUMBER% -b"%SSCM_BRANCH%" -p"%SSCM_REPOSITORY%" -yAdministrator: -z127.0.0.1:4900 >>D:test.log
The TriggerNow we are ready to create the trigger. We will use the "Attach to defect" event to fire the script file.
Creating the TriggerTo create triggers, select "Tools" > "Administration" > "Triggers...".
Figure 6 - Triggers menuThis opens the Triggers window. Click on the "Add..." button. Please review the Surround SCM User Guide for details on how to create triggers. Here is the summary for the trigger I created: Trigger applies to files in branch [WysiCorp Products] and in repository [WysiCorp Products/WysiCalc] [recursively] -- after an event on a [Attach to defect] -- Run script located at "D:batchsetcustomfiel.bat" This trigger will run on my branch called "WysiCorp" and for any file under the "WysiCorp Products" repository or any of its sub-repositories. I saved my batch file on the D:batch folder on the same machine where I have the Surround SCM server running.
What it Looks LikeSo now I checked out all three files separtely shown above in figure 5. I made changes to each file and on check-in, I attached each file to a separate defect. This is what it looks like:
Figure 7 - Defect Number displayed on the Source File List window