I'm trying to prevent issue creation if initiated from a specific URL, i.e. {base-URL}/servicedesk/customer/portal/6/create/27.
I can't find the scriptrunner method required to do this.
Any ideas?
Hi Soeren,
So the referrer URL you posted, if you "decode" it means:
portal - The request came from the portal
6 - The portal id of the project
create - The action
27 - The id of the request type
So, I do not think that you can get the referrer url in a scripted validator, but what you can do is.
For the project with the portal Id 6 and for the request type with id 27 and in the issue creation step to create a validator that will check if the creation came form the portal or not.
Now If the workflow is shared among different projects and/or request types, then a script will be required.
Below is a script that demonstrates how to get a portal id from the project, the id of a request type upon issue creation and finally if the request came from the portal or not.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.MutableIssueimport com.atlassian.servicedesk.api.portal.PortalServiceimport com.atlassian.servicedesk.api.requesttype.RequestTypeService// the issue in creation that triggers the validatordef issue = issue as MutableIssuedef adminUser = ComponentAccessor.userManager.getUserByKey("admin")def portalService = ComponentAccessor.getOSGiComponentInstanceOfType(PortalService)def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)// get issue project and then it's portal iddef project = issue.projectObjectdef portalId = portalService.getPortalForProject(adminUser, project)?.right()?.get()?.id// get issue request type value and get the id of itdef requestTypeCF = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")def requestType = issue.getCustomFieldValue(requestTypeCF)def requestQuery = requestTypeService.newQueryBuilder().issue(issue.id).build()def requestTypeId = requestTypeService.getRequestTypes(adminUser, requestQuery)?.right()?.get()?.results?.find {it.key == requestType?.requestTypeKey}?.id// check if the request comes from portal or notdef objectNode = transientVars."issueProperties".get("request.channel.type")def isFromPortal = objectNode?.get("value")?.textValue == "portal"log.debug "Portal id: $portalId | Request Type Id: $requestTypeId | Is the request comming from the portal ? : $isFromPortal"
If something does not make sense, or if you need further assistance , please ping me.
Kind regards, Thanos
Hello Thanos.
Thanks for your reply - I think I get it.
For now, I'm getting errors:
"
unable to resolve class com.atlassian.servicedesk.api.requesttype.RequestTypeService and unable to resolve class com.atlassian.servicedesk.api.portal.PortalService
" - so I guess something is not loading correctly at our end....
I'll try to get that fixed, and then I'll try your script.
Thanks again for taking the time to help.
Kind regards
Søren
Hey Søren,
I forgot to mention that the above script depends on the ServiceDesk version you are in. So what is your ServiceDesk version ?
Regards, Thanos
Hello Again Thanos.
I'm on version 3.3.0....
Kind regards, Søren
It looks like you're new here. Sign in or register to get started.