It's all about the answers!

Ask a question

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

Andy Jewell (24225669) | asked Apr 07 '14, 8:06 p.m.
edited Apr 07 '14, 8:07 p.m.
 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> );

Any suggestions or examples would be greatly appreciated!


One answer

permanent link
Andy Jewell (24225669) | answered Apr 08 '14, 12:04 p.m.
 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{
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);
IQueryResult<IResolvedResult<IWorkItem>> results = queryClient.getResolvedExpressionResults(project_area, term, IWorkItem.FULL_PROFILE);
while (results.hasNext(monitor)) {
IResolvedResult<IWorkItem> resresult = (IResolvedResult<IWorkItem>) results
IWorkItem item = resresult.getItem();
String strid = Integer.toString(item.getId()); 
log.trace("Found ID {} - {}",strid,item.getHTMLSummary());

        return itemids;

Your answer

Register or to post your answer.