如何在IBM Rational DOORS中仅为指定需求的文本前置需求ID(括号形式)——程序化实现方案咨询
Absolutely, this is fully achievable using IBM Rational DOORS DXL scripting—you’ve got two solid options depending on whether you want to permanently modify the Text attribute or dynamically display the modified content without altering your original data. Let’s break this down:
Option 1: Batch Update the Text Attribute (Permanent Change)
This script will iterate through all objects in your open module, check if "Is Requirement?" is TRUE, and prepend [ID] to the Text content (only if it’s not already there, to avoid duplicates).
The DXL Script
// Batch update Text attribute for requirement objects Module targetModule = current if (null targetModule) { print "Error: Please open a module first before running this script!\n" exit } // Ensure the module is locked for editing if (!isLocked(targetModule)) { lock(targetModule) } Object currentObj for currentObj in targetModule do { // Check if the object is marked as a requirement if (currentObj."Is Requirement?" == TRUE) { string objID = identifier(currentObj) string originalText = currentObj."Text" // Skip if the ID is already prepended to avoid duplicates if (originalText !~ "^\\[" objID "\\]") { currentObj."Text" = "[" objID "] " originalText } } } // Save the changes save(targetModule) print "Success! Updated all qualifying requirement objects.\n"
How to Execute:
- Open the module you want to modify in DOORS.
- Go to
Tools > Edit > DXL Editorto open the script editor. - Paste the code above into the editor.
- Click the
Runbutton (or press F5) to execute the script. - The script will automatically lock the module (if needed), update eligible objects, and save your changes.
Option 2: Use a DXL Computed Attribute (Dynamic, Non-Permanent)
If you don’t want to alter your original Text data, this is the safer approach. We’ll create a new computed attribute that dynamically displays the Text with the [ID] prepended only when "Is Requirement?" is TRUE.
Step-by-Step Setup:
- Open your target module and go to
Tools > Attributes > Edit Attributes. - Click the
Newbutton to create a new attribute. - Configure the attribute:
- Name: Choose something descriptive like
Display Text with ID - Type: Select
DXLfrom the dropdown menu - DXL Field: Paste this code:
string outputText = obj."Text" if (obj."Is Requirement?" == TRUE) { outputText = "[" identifier(obj) "] " outputText } outputText
- Name: Choose something descriptive like
- Click
OKto save the attribute. - Add this new attribute to your module’s column view (right-click column headers >
Insert Column> select your new attribute).
Now, whenever you view the module, this computed attribute will show the modified text for requirements, while your original Text attribute remains untouched.
Key Questions Answered:
- Do I need an additional DXL attribute? Only if you choose the dynamic computed attribute approach (Option 2). For permanent updates (Option 1), you don’t need new attributes—we modify the existing
Textdirectly. - Where do I put the code?
- For Option 1: Paste the script into the DOORS DXL Editor and run it.
- For Option 2: Paste the code directly into the DXL field when creating the new computed attribute.
Pro Tip
Before running any batch modification script (Option 1), it’s always a good idea to make a backup of your module to avoid accidental data loss.
内容的提问来源于stack exchange,提问作者Bijan Sanchez

