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

0 vote
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

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,317 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot