Topic
  • 2 replies
  • Latest Post - ‏2014-01-06T09:05:04Z by Eric.Zhao
Eric.Zhao
Eric.Zhao
2 Posts

Pinned topic CQ Hook中怎么进行多重逻辑查询

‏2013-12-31T06:05:59Z |

Hello,

 

我现在有个叫"Version"的下拉菜单,它的选项依赖于Product,也就是选中一个Product后,Version这个下拉菜单显示相应的选项。

同时我想只显示包含V8或者V9的Version。请问在Hook中怎么做?

下面是我自己的代码,以及网上找到的例子。但是我自己的代码好像不对,它并不是根据Product来显示Version,而是显示了所有Version中包含V8或V9的。

请大家帮忙指导一下。谢谢!


I have a question regarding to structured query in ClearQuest hook:

in my tool, field "Versions" is dependent on field "Product". And I want to display versions contain "V8" or "V9" only. i.e. 
(Product = product name got from current session) AND (Versions like "%V8%" or Version like "%V9%")

Below is my code. it seems it doesn't work well. The Versions field displays items contain V8 or V9, but not dependent on current product. Can you please let me know what issue it is? 

I attached sample code from ClearQuest help in the bottom of this post.

Thanks for your help!

My Code:
-----------------------
Dim sessionObj
Dim filterObj
Dim queryObj
Dim resultSetObj
Dim product

Set sessionObj = GetSession()
product = GetFieldValue("Product").GetValue()
Set queryObj = sessionObj.BuildQuery("Product")

Set filterObj = queryObj.BuildFilterOperator(AD_BOOL_OP_AND)
filterObj.BuildFilter "name", AD_COMP_OP_EQ, product

Set filterObj2 = queryObj.BuildFilterOperator(AD_BOOL_OP_OR)
filterObj2.BuildFilter "versions", AD_COMP_OP_LIKE, "V7"
filterObj2.BuildFilter "versions", AD_COMP_OP_LIKE, "V8"
queryObj.BuildField ("versions")

Set resultSetObj = sessionObj.BuildResultSet(queryObj)
resultSetObj.Execute 

Do While resultSetObj.MoveNext = AD_SUCCESS
choices.AddItem resultSetObj.GetColumnValue(1)
Loop


Sample Code from Clearquest Help:
------------------------------------------------------------------------
VBScript
The following example selects defects that match these criteria:

Planned release of beta 
Not in resolved or verified states 
Priority levels 1 or 2 
Assigned to a certain set of users 
This translates to:

((planned_release = "beta") AND (state != resolved OR verified) AND (priority = 1 OR 2)) OR (assigned_to = lihong OR gonzales OR nougareau OR akamoto)

set session = GetSession

Dim users 
ReDim users(3) ' This sets up an array of four elements 
users(0) = "lihong"
users(1) = "gonzales"
users(2) = "nougareau"
users(3) = "akamoto" 

Dim priority_levels
ReDim priority_levels(1) ' This sets up an array of two elements 
priority_levels(0) = "1"
priority_levels(1) = "2"

Dim states
ReDim states(1)
states(0) = "resolved"
states(1) = "verified"

set querydef = session.BuildQuery("defect") 
querydef.BuildField("id") 
querydef.BuildField("component") 
querydef.BuildField("priority") 
querydef.BuildField("assigned_to.login_name") 
querydef.BuildField("headline") 

set operator = querydef.BuildFilterOperator(AD_BOOL_OP_OR)
set operator2 = operator.BuildFilterOperator(AD_BOOL_OP_AND)
operator2.BuildFilter "planned_release", AD_COMP_OP_EQ, "beta"
operator2.BuildFilter "state", AD_COMP_OP_NOT_IN, states 
operator2.BuildFilter "priority", AD_COMP_OP_IN, priority_levels 

operator.BuildFilter "assigned_to",AD_COMP_OP_IN, users 

set resultset = session.BuildResultSet(querydef)

  • DonaldN
    DonaldN
    287 Posts
    ACCEPTED ANSWER

    Re: CQ Hook中怎么进行多重逻辑查询

    ‏2014-01-06T00:32:58Z  

    Read the sample code again carefully. It will be beneficial to create a query in the ClearQuest GUI to visualize what you are trying to do.

    If you simply want to do it the same way as the sample code, then change

    Set filterObj2 = queryObj.BuildFilterOperator(AD_BOOL_OP_OR)

    to

    Set filterObj2 = filterObj.BuildFilterOperator(AD_BOOL_OP_OR)

  • DonaldN
    DonaldN
    287 Posts

    Re: CQ Hook中怎么进行多重逻辑查询

    ‏2014-01-06T00:32:58Z  

    Read the sample code again carefully. It will be beneficial to create a query in the ClearQuest GUI to visualize what you are trying to do.

    If you simply want to do it the same way as the sample code, then change

    Set filterObj2 = queryObj.BuildFilterOperator(AD_BOOL_OP_OR)

    to

    Set filterObj2 = filterObj.BuildFilterOperator(AD_BOOL_OP_OR)

  • Eric.Zhao
    Eric.Zhao
    2 Posts

    Re: CQ Hook中怎么进行多重逻辑查询

    ‏2014-01-06T09:05:04Z  
    • DonaldN
    • ‏2014-01-06T00:32:58Z

    Read the sample code again carefully. It will be beneficial to create a query in the ClearQuest GUI to visualize what you are trying to do.

    If you simply want to do it the same way as the sample code, then change

    Set filterObj2 = queryObj.BuildFilterOperator(AD_BOOL_OP_OR)

    to

    Set filterObj2 = filterObj.BuildFilterOperator(AD_BOOL_OP_OR)

    Thanks for your help, Donald. Your approach works.

    And i found that the field name is case sensitive ("name" in the script below). When i changed it to "Name", the choice list displayed expected options.

    Set filterObj = queryObj.BuildFilterOperator(AD_BOOL_OP_AND)
    filterObj.BuildFilter "name", AD_COMP_OP_EQ, product