Skip to main content

Field-dependent choicelist hook

This article is brought to you by the Rational staff at developerWorks.

Summary:  This an example of a Dependent Choicelist hook for ClearQuest.

Date:  19 Apr 2004
Level:  Introductory
Activity:  532 views
Comments:  

This item was originally publised in May, 2002.

NOTE: This hook is presented only as an example of how to customize your use of IBM® Rational® ClearQuest®. It has not been formally tested, and is not supported by IBM.

Description

A dependent choicelist typically requires 2 fields: a root field and a dependent field. The root field determines the valid choices for the dependent field. For example, in the HOOKS database, there is a "CQ_Ver" field that captures what version of ClearQuest a particular hook was written for. In version 1.0, ClearQuest only supported Action and Field hooks, and so the possible selections for the "Hook_Type" is limited to "Action" and "Field" while CQ_Ver is set to "1.0". In ClearQuest 1.1, support for Record and Global hooks was added, so when CQ_Ver is set to "1.1", we want to offer these selections also.


Script Language

VB Script


Code

To make the choicelist for the Hook_Type field change based on the currently selected value in the CQ_Ver field, the following choicelist hook was written:

Choicelist hook for field "Hook_type":


Sub Hook_type_ChoiceList(fieldname, choices)
 ' fieldname As String
 ' choices As Object
 'entityDef = Hook

   select case GetFieldValue("CQ_Ver").GetValue
			case "1.0"
			   choices.AddItem "Action"
			   choices.AddItem "Field"
			case "1.1"
			   choices.AddItem "Action"
			   choices.AddItem "Field"
			   choices.AddItem "Record"
			   choices.AddItem "Global"
 			case else
				
		end select

End Sub


In the scenario where a user first selects CQ_Ver "1.1" and Hook_Type "Global", and then changes CQ_Ver to "1.0", the Hook_Type value can be invalid. To prevent this, sometimes it is desirable to clear the content of a dependent field whenever its root field is changed. The following ValueChanged hook for the CQ_Ver field shows this:

ValueChanged hook for field "CQ_Ver":


Sub CQ_Ver_ValueChanged(fieldname)
' fieldname As String
 REM This hook will be run each time the field's value
 REM changes.  This hook is run before
 REM the new value is validated
 REM so be aware the new value may not be valid.
  
  SetFieldValue "Hook_type", ""
  
End Sub


It is also possible that a dependent field could itself be a root field for yet another dependent field. This scenario creates a 3-level hierarchy of dependent fields. In the HOOKS database again, the "Hook_name" field is dependent on the "Hook_type" field, and the example below shows these dependent choices:

Choicelist hook for field "Hook_name":


Sub Hook_name_ChoiceList(fieldname, choices)
  ' fieldname As String
  ' choices As Object
  'entityDef = Hook
    select case GetFieldValue("Hook_type").GetValue
	 case "Field"
		choices.AddItem("Choice_List")
		choices.AddItem("Default_Value")
		choices.AddItem("Permission")
		choices.AddItem("Validation")
		choices.AddItem("Value_Changed")
	case "Action"
		choices.AddItem("Access_Control")
		choices.AddItem("Commit")
		choices.AddItem("Initialization")
		choices.AddItem("Notification")
		choices.AddItem("Validation")
	case "Global"
		 choices.AddItem("Global Hook")
	case "Record"
	 	choices.AddItem("Record Hook")
	case else
		 	
end select
End Sub


Again, because it is desirable to reset dependent fields when their root fields change, we use the following ValueChanged hook on the Hook_type field to reset the content of the Hook_name field:

ValueChanged hook for field "Hook_type":


Sub Hook_type_ValueChanged(fieldname)
 ' fieldname As String
  REM This hook will be run each time the
     field's value
  REM changes.  This hook is run before
  REM the new value is validated
  REM so be aware the new value may not be valid.
  
  SetFieldValue "Hook_name", ""
  
End Sub


If the CQ_Ver field is changed, the CQ_Ver ValueChanged hook will fire. Since it resets (i.e. changes) the Hook_type field, the ValueChanged hook of the Hook_type field will subsequently fire, with the end result being that all dependent fields in the hierarchy are reset.


About the author

This article is brought to you by the Rational staff at developerWorks.

Comments



Trademarks  |  My developerWorks terms and conditions

Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=3864
ArticleTitle=Field-dependent choicelist hook
publish-date=04192004
author1-email=rust@us.ibm.com
author1-email-cc=

My developerWorks community

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Rate a product. Write a review.

Special offers