Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Restrict issue creation with certain symbols

Phil Evans January 21, 2021

Hi.

I want to restrict creation of issues from portal with certain symbols in Summary and Description.

I can put Simple Scripted Validator on workflow creation with

!issue.summary.value.contains("«") && !issue.summary.value.contains("»")

and it works, but how do i use this restriction only for portal request issues creation?

Or please advise how can i use this in Behaviours?

3 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
Phil Evans January 22, 2021

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = issue.getCustomFieldValue(cf)

if ((requestType.toString() == "sdp/96990dda-e6ce-4edb-8df3-29d6bfdf5984") && (issue.description.value.contains("«") || issue.description.value.contains("»") || issue.summary.value.contains("«") || issue.summary.value.contains("»"))) {
return false
}
else {
return true
}

 

To find the requestType string get an issue that has the Request Type that you want to find the id for and:

import com.atlassian.jira.component.ComponentAccessor

def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("Issue Key")
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
issue.getCustomFieldValue(cf)

0 votes
Irfan Mazuki January 21, 2021

Hi @Phil Evans ,

It could be possible to apply the restriction to only portal requests by creating an IF condition that will check if the Request Type field value is not null (All Portal Request Issues would need value in this field). Check out this Community Discussion for some ideas on how the Script to get the Request Type values would look like: Get possible values for Customer Request Type via script runner in Service Desk > v3.3

I hope this helps.

 

Kind regards,
Irfan

Phil Evans January 21, 2021

Hi Ifran.

In Behaviours i can map strictly to the service desk or portal request I want script to work on, but i had no success with the script itself yet.

Phil Evans January 21, 2021

its Irfan, excuse me, @Irfan Mazuki 

Phil Evans January 21, 2021

I am a bit of a newbie with groovy.

This line

!issue.summary.value.contains("«") && !issue.summary.value.contains("»")

does work in Simple Scripted Validator, but it is not recognized when used in Behaviours, and im still grasping why.

Phil Evans January 21, 2021

So i guess in Behaviours it should be a full proper script, not something simple that able to work in Simple Scripted Validator.

Phil Evans January 21, 2021

no success yet

Irfan Mazuki January 21, 2021

Hey Phil, (Thanks for the name correction)

Yes, you're right. Validator is a Workflow function that is triggered when Transitioning Issues, hence the Issue objects are already in place. Behavior needs to be mapped to Issue Types and Projects on a Global-level (Jira instance), so the Issue object is not present yet.

With your requirement, I'd say Validator is the way to go. You can create a script where on top of the condition you have created, it will also check if the Issue has any Request Type value set, to determine if it's a request/issue created from the Portal.

Phil Evans January 21, 2021

Thank you, Irfan.
Gonna go with Validator way.

Phil Evans January 22, 2021

Came up with this but doesnt seem to work with specific request:

 

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = issue.getCustomFieldValue(cf)

if ((requestType == "sdp/96990dda-e6ce-4edb-8df3-29d6bfdf5984") && (issue.description.value.contains("«") || issue.description.value.contains("»") || !issue.summary.value.contains("«") || !issue.summary.value.contains("»"))) {
return false
}
else {
return true
}

Phil Evans January 22, 2021

ok got some NOTs there which shouldnt be there

Phil Evans January 22, 2021

still doesnt work

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = issue.getCustomFieldValue(cf)

if ((requestType == "sdp/96990dda-e6ce-4edb-8df3-29d6bfdf5984") && (issue.description.value.contains("«") || issue.description.value.contains("»") || issue.summary.value.contains("«") || issue.summary.value.contains("»"))) {
return false
}
else {
return true
}

Phil Evans January 22, 2021

ok I think I got it, testing

Phil Evans January 22, 2021

@Irfan Mazuki thank you for guidance.

Irfan Mazuki January 24, 2021

Hey @Phil Evans , great to see you got it working! Thanks for sharing the solution on this post, it'll definitely be helpful to other users facing a similar situation :)

Like Phil Evans likes this
0 votes
Phil Evans January 21, 2021

@Nic Brough -Adaptavist- can you help please?

TAGS
AUG Leaders

Atlassian Community Events