Forums

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

Condition Project exist Script Runner

Deleted user March 30, 2018

Hi,

I trying to automate create project in post function. Everything looks ok, but i have problem with checking of existing of project. I want do this with Condition in transistion, like this:

import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManager = ComponentAccessor.getProjectManager()

// get Key projektu
def Key = customFieldManager.getCustomFieldObject("customfield_17215")
def KeyValue = issue.getCustomFieldValue(Key)

// get klucz
def Projekt = ComponentAccessor.getProjectManager().getProjectObjByKey("$KeyValue") //jeśli nie zwraca Null to znaczy że projekt istnieje

passesCondition = false
if (Projekt == "null"){
passesCondition = true
}
log.debug("Returning: " + passesCondition)

 

sooo default passesCondition is false, but when we have this project in instance (getProjectObjByKey) we have a name, if don't exist then Projekt variable == null, so passesCondition = true. 

 

When i drop values to custom fields everything looks ok. When we have project we have name in custom field, if don't - we have null. Problem is that this doesn't work. I don't have situation when transition is displaying in issue. Can you tell me why?

 

1 answer

1 accepted

0 votes
Answer accepted
Deleted user March 30, 2018

so... null without "" works fine, here is code:

import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.project.Project
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def projectManager = ComponentAccessor.getProjectManager()

// get Key projektu
def Key = customFieldManager.getCustomFieldObject("customfield_17215")
def KeyValue = issue.getCustomFieldValue(Key)

// get klucz
def Projekt = ComponentAccessor.getProjectManager().getProjectObjByKey("$KeyValue") //jeśli nie zwraca Null to znaczy że projekt istnieje

if (Projekt=="" || Projekt==null){
passesCondition = true
}
else
{
passesCondition = false
}


log.debug("Returning: " + passesCondition)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events