Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,299,288
Community Members
 
Community Events
165
Community Groups

Need modified by field JQL using scriptunner

Need user name  for the custom 'Modified By' field when ever the Test case is modified.

The user who modifies a test case is captured. How do I use lastupdated function in JIRA scriptrunner 

 

 

2 answers

A similar code is mentioned here:

https://community.atlassian.com/t5/Jira-questions/Updating-a-custom-field-from-a-script-listener/qaq-p/759053

 

As @Nic Brough _Adaptavist_ mentioned you can tweak the code by getting the logged in user and setting the 'modifed by' custom field. You can get the logged in user by:

def LoggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

 

Hope that helps.

Regards,

Anzar Khan

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.Issue

def issue = event.issue as Issue
def desiredValue = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() //TODO: Change this to be the actual calculation you want
def customFieldName = "Modified By" //TODO: Change this to match the custom field you want
def customFieldManager = ComponentAccessor.customFieldManager
def field = customFieldManager.getCustomFieldObjects(issue).find{
it.name == customFieldName
}
def currentCustomFieldValue = issue.getCustomFieldValue(field)
if (currentCustomFieldValue == desiredValue) {
return //Quit -- we don't want to update the field if it's already correct.
}
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.addCustomFieldValue(field.id, desiredValue)
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def validationResult = issueService.validateUpdate(loggedInUser,
issue.id,
issueInputParameters
)
if (validationResult.isValid()) {
def updateResult = issueService.update(loggedInUser,
validationResult,
EventDispatchOption.DO_NOT_DISPATCH, //This is important to avoid infinite loops
false)
if (!updateResult.isValid()) {
log.error "Failed to update issue $issue.key"
log.error updateResult.errorCollection.errorMessages
log.warn updateResult.warningCollection.warnings
}
} else {
log.error "Failed to update issue $issue.key"
log.error validationResult.errorCollection.errorMessages
log.warn validationResult.warningCollection.warnings
}
0 votes

I'm sorry, I do not understand the question.

It sounds like you want to read a field from some issues, but JQL is about finding issues, not reading fields, so I'm lost on that.  And what "user name" part of the "modified by" - which field are you actually interested in and which user name?

Use of SRs lastupdated  function is documented at https://docs.adaptavist.com/sr4js/latest/get-started/tutorials/jql-functions-tutorial near the bottom of the page.

I have a field by name Modified By . Any  time the test  issue type is updated or edited. The Modified by field should display the persons name who modified it.

Looking for solutions using script runner.

So nothing to do with JQL or searching.

You could write a scripted field to drag it out of the history and comments, or you could write a listener to pick up all the change events (edit, assign, comment, transition, etc) and populate the field with the person who triggered the event.

Like Anzar likes this

Please share scripted field code 

Modified By.PNG                                      Getting error . I created a text custom field by name  'Modified By' and created a listener  as suggested by you. Configured Modified By to Test and Test set issue type. Getting error in the script

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

270 views 2 5
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you