how can i get logged in user in javascript?
9 answers
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.