It's all about the answers!

Ask a question

Writing a script to add users to subscriber - need assistance with subscriber attribute

DH Lee (25784446) | asked Mar 29 '13, 2:59 a.m.
edited Mar 29 '13, 3:59 a.m. by Ralph Schoon (63.2k33646)
My customer is working on a script so that users can be added to subscriber. Their scenario is as below

Customer added a custom attribute called "Referrer" (Contributor list type). They would like users who are selected as "Referrer" to receive WI notification as email. In order to achieve, customer came up with idea that those users who are selected as "Referrer" will be automatically added to Subscriber.

Customer tried

- WorkItemAttributes.SUBSCRIPTER
- WorkItemAttributes.SUBSCRIPTIONS
However they are not able to get value of subscriber nor get attribute name for subscriber.

Could someone please help to get value of subscriber and attribute ID for subscriber?

Accepted answer

permanent link
Ralph Schoon (63.2k33646) | answered Mar 29 '13, 9:16 a.m.
edited Mar 29 '13, 9:17 a.m.
This is currently not possible using JavaScript. You can not access data that is not attribute based, such as Subscribers, attachments, links/relationships using JavaScript.

See for what you can do today.
See for more information.

You can do things like this in Java based Extensions such as Participants. See and related posts as well as for more on this topic.

Also see for another participant that does approvals, but uses API you want. See for how subscriptions work. Be aware the last post uses the Client API, but the server API should be very similar. See for what the differences between client and server API are and why it matters.
Ralph Schoon selected this answer as the correct answer

Nate Decker commented Mar 25 '15, 3:52 p.m. | edited Mar 25 '15, 4:39 p.m.

Ralph, I've seen you post elsewhere that the subscriber client code should be very similar for the server-side code. However, I'm having issues getting it to work. I thought I might try responding here rather than creating a new post on the subject.

For my server-side extension, I've tried getting the working copy and then, for purposes of testing, adding the getAuthenticatedContributor using the getSubscriptions().add method. The participant is super short code-wise.

On the server-side, this doesn't appear to be doing anything. I note that in the client-side code, you don't actually save the work item. I've tried both saving and not saving in my server-side extension, but it didn't matter. I'm not getting exceptions when the participant executes, but nothing changes in the work item. Have you revisited this topic?

Edit: Nevermind. I'm an idiot I guess. I was trying to do this with a JavaScript Attribute Customization before I resorted to doing it via Operation Behavior and forgot to disable the Attribute Customization.

Ralph Schoon commented Mar 26 '15, 4:03 a.m.

Hi Nate. I assume you have solved the problem in your participant. Anyway, the code below would add a subscriber to a work item based on a user ID. You can use the code in and simply replace the approval creation by the code below. How to save is explained in the link.

    private void createSunscriptionFromUser(IWorkItem workItem, String userID, IProgressMonitor monitor) throws TeamRepositoryException {
        IContributorService contributorService = getService(IContributorService.class);
        IContributorHandle subscriber = contributorService
        if (null != subscriber) {
        // Throw some error

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.