Forums

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

java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.user.Application

Yogesh Mude
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, 2021
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName()
ApplicationUser systemUser = ComponentAccessor.getUserManager().getUserByKey("system");
def issueManager = ComponentAccessor.getIssueManager()
CustomField approversCF = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11718) // Approvers custom field
def approversCFValue = issue.getCustomFieldValue(approversCF)
def approvers = []

approversCFValue.each { appUser ->
approvers.add(appUser.getName())
}
log.info "Approvers : " +approvers
if(!approvers.isEmpty()){
if(currentUser in approvers){
approvers.remove(currentUser)
}
issue.setCustomFieldValue(approversCF, approvers)
}
issueManager.updateIssue(systemUser, issue, EventDispatchOption.ISSUE_UPDATED, false)
log.info "after removing approvers : " +approvers

 

1 answer

0 votes
Yogesh Mude
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, 2021

test.JPG

Radek Dostál
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, 2021 edited
def currentUser = ComponentAccessur.getJiraAuthenticationContext().getLoggedInUser().getName()

So you're declaring the currentUser to be String (username). And later on trying to work with it as if it was an ApplicationUser object in

if (currentUser in approvers)
approvers.remove(currentUser) 
Yogesh Mude
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 18, 2021

Thank you @Radek Dostál for your response.

Suggest an answer

Log in or Sign up to answer