April 11, 2012

Custom Numbering with Calculated Fields

Helix ALM
TestTrack has built-in item numbering, giving you the ability to quickly reference a defect or test case by number. What this lacks though is any context or details on the item being referenced. Telling someone "go review test case #432" doesn't provide them with any usable information until they actually jump into TestTrack and start reviewing. This can be a pain for some teams, where item information is passed around a lot via email or informal discussions. If you're in a meeting to triage defects or doing the daily stand-up on project progress, efficiency is important and having one identifier that gives everyone the key details on an item can save time and avoid confusion. To solve this challenge, many customers define their own numbering scheme that in most cases is a combination of several pieces of metadata on the item. So they might abbreviate the product a defect was found in, then tack on the priority along with a unique number and use that as the item "number." With the release of calculated fields in TestTrack 2012, it's much easier to define these custom number formats. For this example, I'm going to setup a pretty simple numbering scheme for test cases that incorporates the product and actual test case number. First step is to create you custom calculated field. [caption id="attachment_11254" align="aligncenter" width="262" caption="Create a custom calculated field"][/caption] With the field created, click Edit down in the Formula area and paste in the code below.var vNumber = Item.fieldValue("Number"); var vPadding = ""; var vPaddedNumber; var vTCNum;// Pad #s so they always have the same number of digits, ensures sorting works. if (vNumber < 1) { vPadding = "0000"; } else if (vNumber < 10) { vPadding = "000"; } else if (vNumber < 100) { vPadding = "00"; } else if (vNumber < 1000) { vPadding = "0"; } // will get us to 9999 // Concatenate Product mapping with padded number. if (vNumber > 0) { vPaddedNumber = vPadding + vNumber; vTestSequence = Item.mappedValue("Product") + "." + vPaddedNumber; } else { vTestSequence = ""; } // last statement sets the return value vTestSequence; A few things of note here:
  • We're padding the actual test case number with extra zeros, so that sorting works correctly. The end result is actually a string, so if you don't pad you'll see that 11 is considered less than 110.
  • product value abbreviations are mapped as shown below.
[caption id="attachment_11256" align="aligncenter" width="533" caption="Define your formula and field mappings"][/caption]