4

I have been searching for a while and could not find a single example...

Using C# and Clearquest API I would like to do something as simple as running a query (for example get a list of CR's by owner)

How do I programatically create a CQ query?

Dave
  • 8,163
  • 11
  • 67
  • 103
RanH
  • 740
  • 1
  • 11
  • 31
  • 1
    SO isn't the place to ask for a general tutorial on a subject; it's a place to ask specific questions that can be given specific answers. – Servy Nov 08 '12 at 17:59
  • 1
    http://www.ibm.com/developerworks/forums/thread.jspa?threadID=78133 if you scroll down a bit on this page a guy named 'Andy Griffin" Gives a decent example –  Nov 08 '12 at 18:04
  • @JustinKirk Thanks it has exactly what I was missing – RanH Nov 08 '12 at 18:33
  • 1
    @Servy I did not ask for a tutorial, just few lines of code to show how to use the buildfield, as it is not exactly as described by IBM... – RanH Nov 08 '12 at 18:53
  • 1
    I'd like to see this re-opened. The question is basically "how do I programatically create a CQ query?", which has a definite answer. I'm not sure how it would solicit debate, etc., from the list of reasons to close it. – Clay Jan 08 '14 at 16:50

2 Answers2

3

Taken from http://www.ibm.com/developerworks/forums/thread.jspa?threadID=78133

SessionClass cqSession = new SessionClass();
cqSession.UserLogon("user", "pass", "dbname", 2,
"");

OAdQuerydef queryDef = (OAdQuerydef)
cqSession.BuildQuery("Issue");
queryDef.BuildField("id");
queryDef.BuildField("summary");

OADQUERYFILTERNODE qfn = (OADQUERYFILTERNODE)
queryDef.BuildFilterOperator(CQConstants.AD_BOOL_OP_AND);
qfn.BuildFilter("description",
CQConstants.AD_COMP_OP_LIKE, "foobar");

OAdResultset rs = (OAdResultset)
cqSession.BuildResultSet(queryDef);
rs.Execute();
RanH
  • 740
  • 1
  • 11
  • 31
  • Sadly, when I try this, `CQConstants` errors with `The name 'CQConstants' does not exist in the current context`, I have added `using ClearQuestOleServer;` as a reference – Dave Jan 03 '17 at 15:24
0

In addition to the answer given above, note ClearQuest provides a file clearquest.bas that has all the constant definitions in there. In order to use that in C# you would create a new file and copy these constant definitions in a new class called CQConstants.

See https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000002903065

If you file an request for an enhancement, the ClearQuest team might consider adding a C# class you could use for the constant definitions.