Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

current user in scriptrunner database picker

Peter Brodt October 10, 2022

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

 

1 answer

1 accepted

0 votes
Answer accepted
Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 10, 2022

@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.

Peter Brodt October 10, 2022

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
Ismael Jimoh
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 11, 2022

@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.

Like • Peter Brodt likes this
Peter Brodt October 12, 2022

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

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.22
TAGS
AUG Leaders

Atlassian Community Events