user creation using sql query

For a given list of projects, find the roles in that project, who the users are in that role, including who the groups are in that role

looking for SQL query for this.

2 answers

This widget could not be displayed.
Micky Caritte Community Champion Dec 07, 2017

Hi Neha,

If you want to read from DB that's OK and you should look at the cwd_membership table which holds relationships between users and groups. Regarding the project roles, the table is projectroleactor (associating roles with actors of type user or group) and projectrole which is the list of available project roles.

here is a query I've used to extract project with their admins. The projectroleid filter can be removed/updated to suit your needs:

SELECT p.id AS 'PID',
pkey AS 'Key',
p.pname 'Name',
ISNULL(u.display_name,'') AS 'Lead',
ISNULL((SELECT COUNT(*) FROM jiraissue GROUP BY project HAVING project = p.ID),0) AS 'Issues',
p.projecttype AS 'Type',
ISNULL((SELECT cname FROM projectcategory WHERE id = (SELECT sink_node_id FROM nodeassociation WHERE source_node_id = p.id AND association_type='ProjectCategory')),'') AS 'Category',
LEFT((
SELECT CONCAT(roletypeparameter, ' (',REPLACE(REPLACE(roletype,'atlassian-',''),'-role-actor',''),')')+', ' AS "text()"
FROM projectroleactor
WHERE pid = p.id AND projectroleid = 10002 AND roletypeparameter <> 'jira-administrators'
FOR XML PATH('')
),255) AS 'Admins'
FROM project p
LEFT JOIN app_user au ON au.user_key = p.lead
LEFT JOIN cwd_user u ON u.lower_user_name = au.lower_user_name

Please note that the query is designed for SQL Server and might be adapted for your database server.

Hope this helps!

Cheers 

Hi Micky,

Thank you for the solution But i tried the same in sql server its not working. moreover I don't want to restrict the role as only admins. 

 

I tried the below query but I dnt think its giving the right result If u can suggest anything on this.

select cwd_group.group_name, cwd_user.user_name, cwd_user.display_name, cwd_user.email_address,
(select attribute_value from cwd_user_attribute where cwd_user_attribute.user_id = cwd_user.id and cwd_user_attribute.attribute_name = "lastAuthenticated") as lastAuthenticated from cwd_membership left join cwd_user on cwd_user.id = cwd_membership.child_user_id left join cwd_group on cwd_membership.parent_id = cwd_group.id order by user_name asc;

Neha Pande

This widget could not be displayed.

Hi Micky,

Thank you for the solution But i tried the same in sql server its not working. moreover I don't want to restrict the role as only admins. 

 

I tried the below query but I dnt think its giving the right result If u can suggest anything on this.

select cwd_group.group_name, cwd_user.user_name, cwd_user.display_name, cwd_user.email_address,
(select attribute_value from cwd_user_attribute where cwd_user_attribute.user_id = cwd_user.id and cwd_user_attribute.attribute_name = "lastAuthenticated") as lastAuthenticated from cwd_membership left join cwd_user on cwd_user.id = cwd_membership.child_user_id left join cwd_group on cwd_membership.parent_id = cwd_group.id order by user_name asc;

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

216 views 3 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you