Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Need modified by field JQL using scriptunner

Garden16_ May 4, 2022

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

Suggest an answer

Log in or Sign up to answer
0 votes
Anzar
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.
May 5, 2022

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

Anzar
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.
May 5, 2022
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
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2022

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.

Garden16_ May 5, 2022

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 5, 2022

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
Garden16_ May 5, 2022

Please share scripted field code 

Garden16_ May 9, 2022

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

TAGS
AUG Leaders

Atlassian Community Events