It's all about the answers!

Ask a question

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


DH Lee (25784146) | asked Mar 29 '13, 2:59 a.m.
JAZZ DEVELOPER
edited Mar 29 '13, 3:59 a.m. by Ralph Schoon (52.6k13541)
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

- com.ibm.team.workitem.quickinformation.kind.subscripter
- com.ibm.team.workitem.quickinformation.kind.subscriptions
- 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 (52.6k13541) | answered Mar 29 '13, 9:16 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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 https://jazz.net/wiki/bin/view/Main/AttributeCustomization#API_for_Javascript for what you can do today.
See https://jazz.net/library/article/1093 for more information.

You can do things like this in Java based Extensions such as Participants. See http://rsjazz.wordpress.com/2013/02/28/setting-up-rational-team-concert-for-api-development/ and related posts as well as https://jazz.net/library/article/1000 for more on this topic.

Also see http://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ for another participant that does approvals, but uses API you want. See http://rsjazz.wordpress.com/2012/08/02/subscribing-to-a-work-item-using-the-java-api/ for how subscriptions work. Be aware the last post uses the Client API, but the server API should be very similar. See http://rsjazz.wordpress.com/2013/03/14/what-apis-are-available-for-rtc-and-what-can-you-extend/ for what the differences between client and server API are and why it matters.
Ralph Schoon selected this answer as the correct answer

Comments
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.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

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 https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ 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
                .fetchContributorByUserId(userID);
        if (null != subscriber) {
            workItem.getSubscriptions().add(subscriber);
        }
        // Throw some error
    }

Your answer


Register or to post your answer.