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
A similar code is mentioned here:
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
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.