Hi folks,
I have implemented two database pickers for jira projects and confluence spaces. Is there a possibility to get the current user in order to include it into the sql.
Peter
@Peter Brodt how are you connecting to the database?
Via script or via the Local Database Connector?
If the former, then using the normal getcurrentloggedinuser() method should already achieve this and you parse your query to the database (recommend this only for select).
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
See here on how to connect to a database.
For a direct connection to via the database, I am not sure you can parse the current logged in user because this is a direct SQL query and even if you are correct, it will likely parse the user the application (JIRA or Confluence) uses to connect to the database.
Regards.
Hi Ismael,
sorry I was definitely not clear in my question. I meant a Scriptrunner Database Picker.
This is the retrieval SQL and I would like to limit the projects to the ones the current user has access to. But therefore I need some kind of a function to get the current user.
SELECT
p1.id, p1.pname || ' (' || p1.pkey || ')' Projekt
FROM
project p1
WHERE
p1.id = cast(? as numeric)
AND NOT p1.pkey IN (
SELECT
p2.pkey
FROM
propertyentry pe
JOIN project p2 ON pe.entity_id = p2.id
WHERE
property_key = 'jira.archiving.projects')
ORDER BY Projekt ASC
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Peter Brodt the above method you use would not allow you parse the current user in the database picker.
You will need to write a script that does what you are selecting and parse the current user via the script to my knowledge.
Regards.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
that's what I feared. I thought that perhaps there is some kind of a scriptrunner function which retrieves the current user and passes it to the sql as a bind variable.
Thanks for your support Ismael.
Regards,
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.