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!
|
9 answers
Ralph Schoon (63.5k●3●36●46)
| answered Dec 04 '11, 7:54 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
As stated in the other thread, I don't think this is possible.
|
You can get the logged in user in javascript with the following lines of code:
You can inspect the used objects from some other information you may need in your scripts. Hope this helps! Regards, Jorge. |
Ralph Schoon (63.5k●3●36●46)
| answered Dec 05 '11, 3:19 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. |
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. |
Ralph Schoon (63.5k●3●36●46)
| answered Dec 05 '11, 7:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
So I must currently assume that this not accessible at least in the Javascript API that is provided for Attribute customization. |
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. |
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: |
Ralph Schoon (63.5k●3●36●46)
| answered Mar 16 '12, 3:24 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. |
Ralph Schoon (63.5k●3●36●46)
| answered May 21 '15, 4:01 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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.
|
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.