• Community
  • Products
  • Jira
  • Questions
  • No such property: transientVars -- String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

No such property: transientVars -- String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

Below code throws no such property: transientVars for the below code:

import com.opensymphony.workflow.WorkflowContext

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.ComponentManager

import com.atlassian.jira.event.issue.AbstractIssueEventListener

import com.atlassian.jira.event.issue.IssueEvent

import org.apache.log4j.Logger

import static org.apache.log4j.Level.DEBUG

import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult

import com.atlassian.jira.bc.issue.IssueService.IssueResult

import com.atlassian.jira.bc.issue.IssueService

import com.atlassian.jira.bc.issue.IssueService.TransitionValidationResult

import com.atlassian.jira.issue.IssueInputParametersImpl

import com.atlassian.jira.issue.IssueInputParameters

import com.atlassian.jira.util.ErrorCollection

import com.atlassian.jira.issue.index.IssueIndexManager

import java.sql.Timestamp

import com.atlassian.jira.issue.comments.CommentManager

import com.atlassian.crowd.embedded.api.User

import com.atlassian.jira.component.ComponentAccessor

import com.opensymphony.workflow.WorkflowContext

class SummaryStatusDate extends AbstractIssueEventListener {

Logger log = Logger.getLogger(SummaryStatusDate.class)

@Override

void workflowEvent(IssueEvent event) {

log.setLevel(org.apache.log4j.Level.DEBUG)

def field = event.getChangeLog().getRelated('ChildChangeItem').any{ it.field.toString().equalsIgnoreCase("Summary Updated")}

if (field){

def today = new Date()

log.debug "Date: " + today

Issue issue = event.getIssue()

//String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

//User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

//User user = event.getUser()

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();

log.debug "i'm here: " + currentUser

//User currentUserObj = UserUtils.getUser(currentUser);

ComponentManager componentManager = ComponentManager.getInstance()

CommentManager commentManager = componentManager.getCommentManager()

commentManager.create(issue, user, "Comment automatically generated...", false)

}

}

}

2 answers

1 accepted

4 votes

Hello,

you can easily retrieve caller just using getUser method from event

String currentUser = event.getUser().getName();

Please, take care that CommentManager create methods need an ApplicationUser and not a User.

In this way, you can use the following approach :

...
ApplicationUser user = ComponentAccessor.getJiraAuthenticationContext().getUser();
...

Hope this helps,

Fabio

0 vote

In future can you use the "code" formatting from the toolbar, otherwise the code is more or less unreadable.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

158 views 1 17
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