Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to use ParameterVariable using plain java API to run parameterized query?

 Hi. . . I'm trying to run a shared query that has a run-time variable - i.e., when the user runs it from the UI RTC prompts them for a value for the variable expression.  I've search this site as well as Ralph Schoon's blog but didn't find anything.

I've found the query.setParameterValues(arg0) method and it seems promising but I'm not sure how to set up an Expression:

ParameterVariableContext ctx = new ParameterVariableContext();
addVariableValue("value to match?", <Expression> );
query.setParameterValues(ctx);

Any suggestions or examples would be greatly appreciated!

Andy

0 votes



One answer

Permanent link
 I didn't find out exactly how to replace parameterized expressions in a saved query, I guess in my case it wasn't strictly required.  I used some code from Ralph (link above) to just create a query on the fly that served my purpose:

public List<String> findWorkitemsByIssue(String issuenumber) throws TeamRepositoryException{
log.trace("entered");
String propname = "Summary";
        List<String> itemids = new ArrayList<String>();
IQueryClient queryClient = client.getQueryClient();
IQueryableAttribute idAttribute = findAttribute(propname);
log.debug("for custom attribute {}, found attr (displayname) {}",propname,idAttribute.getDisplayName());

AttributeExpression summaryContains = new AttributeExpression(idAttribute,AttributeOperation.CONTAINS, issuenumber);
IQueryableAttribute projectAreaAttribute = findAttribute(IWorkItem.PROJECT_AREA_PROPERTY);
	AttributeExpression projectAreaExpression = new AttributeExpression(
projectAreaAttribute, AttributeOperation.EQUALS, project_area);
Term term = new Term(Operator.AND);
term.add(projectAreaExpression);
term.add(summaryContains);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(project_area, term, IWorkItem.FULL_PROFILE);
results.setLimit(Integer.MIN_VALUE);
while (results.hasNext(monitor)) {
IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results
.next(monitor);
IWorkItem item = resresult.getItem();
String strid = Integer.toString(item.getId()); 
log.trace("Found ID {} - {}",strid,item.getHTMLSummary());
itemids.add(strid);
}

        return itemids;
}

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,014
× 411
× 169

Question asked: Apr 07 '14, 8:06 p.m.

Question was seen: 5,573 times

Last updated: Apr 08 '14, 12:04 p.m.

Confirmation Cancel Confirm