It's all about the answers!

Ask a question

How can I get the URL from a Changeset on a Participant?

Fran Burgos (12312352) | asked Jul 21 '17, 7:08 a.m.
edited Jul 21 '17, 7:10 a.m.

When a change set is accesed via web browser you have an url address with this format:    


I have a Participant for sending notifications when a delivery is performed. I resolve the change sets with:
List<IChangeSet> changeSets = auditableServer.resolveAuditables(changeSetHandles, ItemProfile.<IChangeSet>createFullProfile(IChangeSet.ITEM_TYPE, true), monitor);

And I would like fetch the URL but I didn't find any method on IChangeSet or a Service to use for get this information. All I found is about WorkItem related artifacts associated.
How can I get the URL?

Accepted answer

permanent link
Ralph Schoon (63.2k33646) | answered Jul 21 '17, 9:02 a.m.
edited Jul 21 '17, 9:11 a.m.

The data usually does not provide a URL, you have to compute that. For any element, you can use .origin() to get the team repository and from that you can get the public URI e.g.

((ITeamRepository) workItem.getOrigin()).publicUriRoot()

You can use to create URI's

Location location = Location.namedLocation(workItem, ((ITeamRepository) workItem.getOrigin()).publicUriRoot());

You can use the Location to get the URI/URL.

Note there are different Location types namedLocation, itemLocation and you would have to look at the URL of an existing item to see the pattern and find out which location to use.

I usually use existing data and print that to understand what is supposed to be there.

for some related code (you can get URI's from references and create them from URI's.

There is also code that creates URI's in  the WCL:

Fran Burgos selected this answer as the correct answer

Fran Burgos commented Jul 25 '17, 6:31 a.m.

Finally I did with: 
URI uri = ChangeSetLocationFactory.createChangeSetWebURL(changeSetsHandle, targetWorkspace, getPublicRepositoryURL(), null);

As you noticed nameLocation and itemLocation are different. nameLocation works fine with WorkItems and itemLocation with Changesets and Workspaces (nameLocation on changeSets throws an IllegalStateException because referenced item has not defined a naming identifier). But when you use itemLocation on a Changeset the URI's result doesn't use the context (target workspace) hence with ChangeSetLocationFactory you get the complete URL with the worspace context too.

Your answer

Register or 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.