Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

how can i get logged in user in javascript?

i use RTC in 3.0.1. I using scripts for attribute customization in work item to validate something. but i don't get current user in script. How can i to do it? What function can get curent user in script? Can you provide some API and some example ? Thank you!

0 votes



9 answers

Permanent link
As stated in the other thread, I don't think this is possible.

0 votes


Permanent link
You can get the logged in user in javascript with the following lines of code:


dojo.require("com.ibm.team.repository.web.client.session.Session");

// get the Session object
var Session = com.ibm.team.repository.web.client.session.Session;

// get the AuthenticatedContributor info object from the session
var getAuthenticatedContributor = com.ibm.team.repository.web.client.session.getAuthenticatedContributor;

// get the user ID
var userId = getAuthenticatedContributor().userId;


You can inspect the used objects from some other information you may need in your scripts.

Hope this helps!

Regards,

Jorge.

0 votes


Permanent link
Hi Jorge,

thanks for the snippet, I will add it to my example collection. Can you use this to set the user in some contributor attribute script too? I was unable to do so in an experiment I did recently.

0 votes


Permanent link
You mean for example in a calculated value or default one? Yes, I don't see why you wouldn't.

I personally have this code in a js helper library for reuse by my various javascripts that need to know about the user.

Please give a try and I can try to help if you find any problems.

Regards,

Jorge.

0 votes


Permanent link
Hi Jorge,

I tried that in the context of a Calculated Value Provider and the dojo.require() statement for the Session object prevents the script from loading. The internal scripting engine does not have the session object exposed.
https://jazz.net/wiki/bin/view/Main/AttributeCustomizationExamples#Get_an_item_s_UUID_users_iterati indicates that there is no access to the logged in user.


Solution: There is no direct way of getting the user id from the UI,...


So I must currently assume that this not accessible at least in the Javascript API that is provided for Attribute customization.

0 votes


Permanent link
For logging purposes, after checking with Ralph:

for Attribute Customization scripts there seem to be no way of gettting the user ID. For customizations that contribute to the UI (like creating a Web Action or an Attribute Presentation), the Session javascript class can be used to retrieve user ID information.

Regards,

Jorge.

0 votes


Permanent link
Sorry for resurrecting the topic but I would like to know if this is possible:

I've tried the code linked by Ralph for detecting the logged in user by checking with the work item creator:

workItem.getValue(WorkItemAttributes.OWNER);

but that line won't work unless the WI is saved, correct?

I needed to discover the logged in user for it needs to be passed as an argument to a query executed through a Calculated Value Custom Attribute. Is there any way of accomplishing this?

regards,

ggalvao

For logging purposes, after checking with Ralph:

for Attribute Customization scripts there seem to be no way of gettting the user ID. For customizations that contribute to the UI (like creating a Web Action or an Attribute Presentation), the Session javascript class can be used to retrieve user ID information.

Regards,

Jorge.

0 votes


Permanent link
Hi,

I have not found a way to discover the logged in user with scripts. As far as I remember I was also pretty unsuccessful with the owner attribute in scripts. The link mentioned in the thread above indicates that there is currently only limited support for IItem objects. For the owner etc. I was able to retrieve an item ID, but there are no operations I am aware of that would allow to get the name etc.

Having said that, there is a way to get the logged in user (authenticated user) using the default value customization. You might be able to use a hidden attribute that you set using this. I am not sure however.

0 votes


Permanent link
Please see answer https://jazz.net/forum/questions/133477/work-item-customization-getting-current-user-as-logged-in-user/184711 for how to get the item ID for the user that runs the operation. Thanks to Amaury Quintero for providing this info.

0 votes

Your answer

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

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,927

Question asked: Dec 03 '11, 9:51 p.m.

Question was seen: 16,276 times

Last updated: May 21 '15, 4:01 p.m.

Confirmation Cancel Confirm