Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with JMWE 'Scripted (Groovy) Validator'

Sadath Ali Syed February 9, 2022

I am using 'Scripted (Groovy) Validator' on a Jira SD project workflow on create transition. Though the condition is false, I am able to create an issue. After the issue is created, when I go to the validator and 'Test Groovy Script' for the created issue, it is returning false. Not sure how the issue is getting created in first place. Any idea?

2 answers

1 accepted

0 votes
Answer accepted
David Fischer
Community Champion
February 9, 2022

Hi @Sadath Ali Syed ,

it probably means that the condition actually returns true during the issue creation. It could be because Jira Service Management does not set a field value "on time" for the validator to see it.

If you share your validator code, I might be able to figure out what could be wrong.

Sadath Ali Syed February 9, 2022

if ((issue.getAsHtml("attachment").endsWith("pdf")) && (issue.get("customfield_11907") != "Yes")) {
return false
}
else {
return true
}

Sadath Ali Syed February 9, 2022

@David Fischer - The requirement is to enforce users to set one of the radio buttons field to Yes when they attach a pdf attachment.

David Fischer
Community Champion
February 9, 2022

You can't test the attachment field for that, as the attachments are not yet added to the issue when the validator runs (in case validation fails).

To access the attachments added on the transition screen, use the getTransitionAttachments() global function:

issue.get("customfield_11907") == "Yes" || !getTransitionAttachments()?.any{it.mimetype == "application/pdf"}  
Sadath Ali Syed February 9, 2022

@David Fischer - Getting the below error when I use the above. Am I doing something wrong here.

Message:
groovy.lang.MissingMethodException: No signature of method: script_3409a5defb8f9b2823960a64d5a35675.getTransitionAttachments() is applicable for argument types: () values: []
David Fischer
Community Champion
February 9, 2022

Are you using the latest version of JMWE?

Sadath Ali Syed February 9, 2022 edited

@David Fischer I updated to latest version of JMWE and doesnt get the above error. However, the code you provided is returning true even if the custom field is not 'Yes'. Could you please help me with it.

David Fischer
Community Champion
February 10, 2022

@Sadath Ali Syed you tested it after publishing the workflow, right? Not in the Groovy Tester which won't see attachments since there is no current transition running during testing.

Sadath Ali Syed February 10, 2022

@David Fischer - Yes, I did publish the workflow and created ticket attaching pdf and marking the custom field as No. I was able to create ticket. I should have thrown error message from the validator, but it did not.

David Fischer
Community Champion
February 10, 2022

@Sadath Ali Syed was the attachment fully loaded when you clicked on Create? It might take some time for Jira to upload the attachment, there's a progress bar that appears and it must be gone.

Also, was it a real PDF file? The code I shared looks at the mime type, if you want you can switch back to just checking the extension:

issue.get("customfield_11907") == "Yes" || !getTransitionAttachments()?.any{it.filename.endsWith("pdf")}  
Sadath Ali Syed February 10, 2022

Thanks a million @David Fischer . This is working.:) 

0 votes
Shaikha Alketbi January 23, 2024

I am having same issue my Test Groovy Script for the created issue, it is returning false but i am still able to create the issue

 

My Script :


def issueType = issue.issueTypeObject
def priority = issue.priorityObject

if (issueType.name == 'Emergency Change' && !(priority.name == 'P1' || priority.name == 'P2')) {
return false
}

return true

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence, loom, atlassian intelligence, ai notes, ai-powered meeting notes, atlassian community events, ace, confluence ai, loom ai integration, ai note-taking, atlassian ai features, team '25, atlassian live learning, confluence automation

Unlock AI-powered meeting notes: Join our live learning session! 📹

Did you catch the news at Team ‘25? With Loom, Confluence, Atlassian Intelligence, & even Jira 👀, you won’t have to worry about taking meeting notes again… unless you want to. Join us to explore the beta & discover a new way to boost meeting productivity.

Register today!
AUG Leaders

Atlassian Community Events