Script Workflow Validator Help

Phil Pearce August 6, 2013

I have written the following script to run on the Create workflow transition and it always retrurns False. I have tested it using the Script Console manually retrieving an issue and it works. Are you able to help with this??


import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue

ComponentManager componentManager = ComponentManager.getInstance()

//issue = componentManager.getIssueManager().getIssueObject("PROP-1310")
pcm = componentManager.getProjectComponentManager()

pc = pcm.findComponentsByIssue(issue)

CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
CustomField cf= customFieldManager.getCustomFieldObject("customfield_12114")

boolean res
res = false
for (c in pc) {
    switch (c.getName()) {
        case ['test', 'test2']:
            if (cf.getValue(issue).toString() == 'Supplier1') {
                res = true
            } else {
                res = false
            }
            break

        default :
            res = false
    }
}
return res

3 answers

0 votes
Phil Pearce August 12, 2013

How can you access/set the pre saved Issues values?

0 votes
Phil Pearce August 12, 2013

Hi Bhushan,

Unfortunately this has not worked. I believe the problem is that the Issue has not yet been created in the database on the Create Validator

Udo Brand
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 12, 2013

You're correct, validation comes before the postfunction and there the first step is 'Create the issue originally', so the issue hasn't been created at that stage.

0 votes
Bhushan Nagaraj
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2013

Hey Phil,

Try changing

if (cf.getValue(issue).toString() == 'Supplier1')

to

if (cf.getValue(issue).toString().equals('Supplier1'))

Cheers

Bhushan

Suggest an answer

Log in or Sign up to answer