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.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.servicedesk.api.portal.PortalService
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
// the issue in creation that triggers the validator
def issue = issue as MutableIssue
def adminUser = ComponentAccessor.userManager.getUserByKey("admin")
def portalService = ComponentAccessor.getOSGiComponentInstanceOfType(PortalService)
def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)
// get issue project and then it's portal id
def project = issue.projectObject
def portalId = portalService.getPortalForProject(adminUser, project)?.right()?.get()?.id
// get issue request type value and get the id of it
def 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 not
def 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Again Thanos.
I'm on version 3.3.0....
Kind regards, Søren
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Søren,
I tested it on a 3.3.0 version and it seems to work. Can I ask you if you have the script inline or you have it in a file ?
Are the errors you get coming from the logs or you see those errors in the UI ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Thanos
The script is inline, and the errors are from the UI.
Kind regards
Søren
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey Søren
It is possible those errors to be static type checking errors.
In that case you can ignore them and see if there are any real problems by checking your application logs.
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.