Hello,
I am trying to hide the "Create sub-task" button on a specific project, if the user performing the action (current user) is not in a specific user picker custom field.
What I have so far:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.Issue;
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()def customFieldManager = ComponentAccessor.getCustomFieldManager()
def resp = customFieldManager.getCustomFieldObjectsByName("Responsible")String username = issue.getCustomFieldValue(resp).name
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(username);
if (!issue.getProjectObject().getKey() == "ProjectA") { return true
}else {
boolean condition = (issue.getProjectObject().getKey() == "ProjectA" && currentUser != user.name)
log.error("condition : " + condition)
condition
}
My problem is that it works for projectA (hides the sub-task create button from the "More" menu) if the current user is not the responsible, but for all other projects it is not showing the button anymore, like the if condition does not exist.
Please let me know your thoughts.
Thank you.
Hi @arama mihai
For your requirement, you could try something like this:-
import com.atlassian.jira.component.ComponentAccessor
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
if(issue != null && jiraHelper.project?.key == "TPA" && loggedInUser.name == "ram") {
false
} else {
true
}
Please note, this sample code is not 100% exact to your environment. Hence, you will need to make the required modifications.
This is a working code that I have tested in my environment. Basically, if the currently logged-in user is ram, the user cannot specifically create sub-tasks for the TPA project. Other users, on the other hand, will be able to create the sub-tasks. For other projects, this user will be able to create the sub-tasks.
I hope this helps to answer your question. :)
Thank you and Kind Regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
Thank you, that was very helpful for my final solution:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def resp = customFieldManager.getCustomFieldObjectsByName("Responsible")
def coord = customFieldManager.getCustomFieldObjectsByName("Coordinator")
if (jiraHelper?.project?.key == "abc") {
String usernameResp = issue.getCustomFieldValue(resp).name
String usernameCoord = issue.getCustomFieldValue(coord).name
ApplicationUser user1 = ComponentAccessor.getUserManager().getUserByName(usernameResp);
ApplicationUser user2 = ComponentAccessor.getUserManager().getUserByName(usernameCoord);
def approvedUsers = [user1.name, user2.name]
currentUser.name in approvedUsers
}
else {true}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.