Hello,
I use Adaptavist ScriptRunner for JIRA Cloud addons and it's awesome.
Problem i have... i need to add some script who modify issue fields but when i execute some script with it : all my user receive an notification : Change By : Adaptavist ScriptRunner for JIRA Cloud.
Is it possible to add on the script : DO NOT SEND notification with the update ?
Thanks a lot.
Regards.
Paul
Hi :)
Theses settings is about when the script is failed :
"The group to which email notifications will be sent if a script fails to execute"
And
"Send notifications to the Assignee and Reporter of an issue if a script fails to execute"
My goal is to remove notifications for issues updated by the script.
Thanks for your answer but i think, it's impossible to remove system notifications by script...
You need to create a notification scheme that doesn't send any notifications. At the start of your script you need to change the project notification scheme to this new one (https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-project-projectIdOrKey-put). At the end of the script you can revert the change to the original one.
I was able to do it programmatically in ScriptRunner (without using Rest API):
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.notification.NotificationSchemeManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.util.UserManager
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
def projectManager = ComponentAccessor.getProjectManager()
def issueManager = ComponentAccessor.getIssueManager()
def commentManager = ComponentAccessor.getCommentManager()
def userManager = ComponentAccessor.getUserManager()
def notificationSchemeManager = ComponentAccessor.getNotificationSchemeManager()
// delete all comments for given issue in given project
def issue = issueManager.getIssueObject("issue_key")
def project = projectManager.getProjectObjByKey("project_key")
log.debug(project.getName())
def notificationScheme = notificationSchemeManager.getSchemeFor(project)
if (notificationScheme != null){
log.debug(notificationScheme.getName())
notificationSchemeManager.removeSchemesFromProject(project)
}
for(comment in commentManager.getComments(issue)){
log.debug(comment.getBody())
def user = comment.getAuthorApplicationUser()
log.debug(user.getName())
commentManager.delete(comment, false, null)
}
if (notificationScheme != null){
notificationSchemeManager.addSchemeToProject(project, notificationScheme)
}
You can add this line to your REST call:
.queryString("notifyUsers", Boolean.FALSE)
For ScriptRunner Cloud maybe you're doing something like this in your script:
put("/rest/api/2/issue/${issue.key}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()
Try adding the following line:
.queryString("notifyUsers", Boolean.FALSE)
Which would result in something like:
put("/rest/api/2/issue/${issue.key}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.queryString("notifyUsers", Boolean.FALSE)
.header("Content-Type", "application/json")
.body([
fields:[
(outputCfId): output
]
])
.asString()
This is based on the documentation of the Issue endpoint and there's a few ifs and buts to read in the link (the user that the script is executed by must have some admin privileges).
Thank you! Immensely helpful
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.event.type.EventDispatchOption
IssueService issueService = ComponentAccessor.getIssueService()
def user = currentUser
def cf =ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(issue).find {it.name == 'xxxx'}
issueInputParameters.addCustomFieldValue(cf.id, "Hello, world!")
issueInputParameters.setSkipLicenceCheck(true)
issueInputParameters.setSkipScreenCheck(true)
issueInputParameters.setApplyDefaultValuesWhenParameterNotProvided(true)
def update = issueService.validateUpdate(user, issue.id, issueInputParameters)
if (update.isValid()) {
issueService.update(user, update, EventDispatchOption.DO_NOT_DISPATCH, false)
}
issueInputParameters = issueService.newIssueInputParameters()
the idea is to update an issue by yourself through issueService where you can control sending e-mail (the last param == false)
and then pass an empty issueInputParametrs to the execution pipeline