Is there a way to bypass or prevent an Update listener from triggering when making an update via an API update?
It is a Data Centre installation.
A Groovy Class is used in ScriptRunner to make the Update, as this is primarily to update the Organizations field which i believe is not updateable with setCustomFieldValue.
public class API {
static java.lang.String baseUrl = ComponentAccessor.applicationProperties.getString(APKeys.JIRA_BASEURL)
static RESTClient PostClient = new RESTClient(baseUrl)
API() {
PostClient.encoderRegistry = new EncoderRegistry(charset: 'UTF-8')
PostClient.setHeaders([
//ASIWorkerBee - ASI SD Automation
Authorization : "Bearer #####",
"X-Atlassian-Token": "no-check",
"X-ExperimentalApi" : "opt-in"
]
)
}
public static Post(String Path, def PayLoad){
return PostClient.post(
path: Path,
contentType: ContentType.JSON,
body: PayLoad
)
}
public static def Put(String Path, def PayLoad){
try {
def Result = PostClient.put(
path: Path,
contentType: ContentType.JSON,
body: PayLoad,
)
} catch (Exception e) {
//e.statusCode
//e.response.data
}
}
}
I don't think there is any way to suppress the events when calling the REST API.
But it absolutely IS possible to update the Organizations field with setCustomFieldValue.
The trick is that you have to find the correct "CustomerOrganization" object using the OrganizationService.
If you know the id, then it's easy:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.onresolve.scriptrunner.runner.customisers.PluginModule
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def jsdOrgId = 12345 //the ID of the org you want to apply to the issue
@PluginModule OrganizationService organizationService
def jsdOrg = organizationService.getById(currentUser, jsdOrgId as Integer)
issue.setCustomFieldValue(orgCf, [jsdOrg])
ComponentAccessor.issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false)
//don't forget to re-index the issue after the update
If you only know the name, I know of no way to find it other than loop through all orgs (that could take a while if you have a large list).
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.util.paging.SimplePagedRequest
import com.onresolve.scriptrunner.runner.customisers.PluginModule
@PluginModule OrganizationService organizationService
@PluginModule ServiceDeskManager serviceDeskManager
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def orgNameToFind = 'some name to find'
def projectKey = 'ABC'
def project = ComponentAccessor.projectManager.getProjectByCurrentKey(projectKey)
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(project)
def orgQueryBuilder = organizationService.newOrganizationsQueryBuilder().serviceDeskId(serviceDeskProject.id)
def iPage = 1
def organization
while (true) {
def orgQueryResults = organizationService.getOrganizations(currentUser, orgQueryBuilder.build())
organization = orgQueryResults.results.find {
it.name.equalsIgnoreCase(orgNameToFind)
}
if (organization) {
log.info "found $orgNameToFind in orgQueryResults page $iPage"
break
}
if (!orgQueryResults.hasNextPage()) {
break
}
def pagedRequest = SimplePagedRequest.newInstance(orgQueryResults.pagedRequest.start + orgQueryResults.pagedRequest.limit, 50)
orgQueryBuilder.pagedRequest(pagedRequest)
iPage++
}
if (!organization) {
log.error "No organization was found matching '$orgNameToFind' after looping through $iPage pages worth of organizations for project $projectKey"
}
organization
Thank You @Peter-Dave Sheehan
Just what I needed, removed some other complexities also.
We have more detail for our Organizations stored in Insight Objects, and this includes the Service Desk Organization ID, so no need for us to search through by name for this use case.
Thanks again.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, yeah!
I have exactly the same setup.
Customers are linked to User object which are linked to company objects.
The Insight custom field defaults to the company object and I use a post function to fetch the JSD Org ID from the object and apply the organization to the ticket for automatic sharing.
Glad I could help.
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.