It's all about the answers!

Ask a question

Setting priority within a participant


Susan Hanson (1.6k2169193) | asked Aug 27 '14, 5:52 p.m.
I'm sure this is really easy, but for the life of me, I can't get it to work.

I am in a Server-side participant for a WorkItemSave and I just need to set the value of the Priority built-in attribute.

I have the workingCOpy, and I can do workingCopy.setPriority(iPriorityIdentifier); and then _service.saveWorkItem3();

but the setPriority takes an Identifier<IPriority> which I am struggling to get.  
Anybody have a snippet they can help me with?

Susan

Accepted answer


permanent link
sam detweiler (12.4k6173200) | answered Aug 27 '14, 6:10 p.m.
well, the priority is an enum, enums have ILiterals and these have identifiers.
from my dump workitem utility

// this will throw exception if not enumeration
                            IEnumeration<ILiteral> enumeration = (IEnumeration<ILiteral>) workItemCommon
                                    .resolveEnumeration(ia, monitor);
                            if (enumeration != null)
                            {
                                String[] iaval = ia
                                        .getValue(auditableClient, workItem,
                                                monitor).toString().split(":");
                                if (iaval.length > 1 && iaval[1] != null)
                                {
                                    List<ILiteral> enumerationLiterals = enumeration
                                            .getEnumerationLiterals();
                                    for (ILiteral literal : enumerationLiterals)
                                    {
                                       Identifier i=literal.getIdentifier2();  <------
                                        if (literal.getIdentifier2()
                                                .getStringIdentifier()
                                                .equalsIgnoreCase(iaval[1]))
                                        {
Susan Hanson selected this answer as the correct answer

Comments
Susan Hanson commented Aug 27 '14, 9:36 p.m.

Right, I have almost all of that already, but am missing the IAttributeHandle for Priority to pass in.
private Identifier getLiteralEqualsString(String name, IAttributeHandle ia) throws TeamRepositoryException {
  IWorkItemServer wiService = (IWorkItemServer) getService(IWorkItemServer.class);
  Identifier literalID = null;
  IEnumeration en = wiService.resolveEnumeration(ia, null);
  List literals = en.getEnumerationLiterals();
        for (Iterator iter = literals.iterator(); iter.hasNext();) {
            ILiteral iLiteral = (ILiteral) itor.next();
            if (iLiteral.getName().equals(name)) {
                literalID = iLiteral.getIdentifier2();
                break;
            }
        }
        return literalID;
    }


Susan Hanson commented Aug 27 '14, 9:52 p.m.

nevermind .. duh
IAttribute prioAttr = _service.findAttribute(workItem.getProjectArea(), IWorkItem.PRIORITY_PROPERTY, null);

All is working now!

Your answer


Register or to post your answer.