Hi,
I wanted to compare my unreleased version with user selected version picker value.
but the problem is when I use this code
def releaseVerField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Target Version")
def releaseVerFieldValue = issue.getCustomFieldValue(releaseVerField)
it retrieves [19.2.8] with bracket, how can cast this List to String.
I am in a real need of help, can anyone with this below code.
Since I am new to groovy so,
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.project.version.VersionManager
import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.ProjectImplComponentManager componentManager = ComponentManager.getInstance()
VersionManager versionManager = ComponentAccessor.getVersionManager();
def releaseVerField = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Target Version")
def releaseVerFieldValue = issue.getCustomFieldValue(releaseVerField)
log.warn(releaseVerFieldValue)List<VersionManager> versions=versionManager.getVersionsUnreleased(10207,true) as List
def tarversion= versions.iterator().next().toString()if (releaseVerFieldValue !=tarversion)
{
log.warn(versions.iterator().next())
return true
}
else
throw newInvalidInputException("Target version must be unreleased");
Output:
Thanks & Regards
You can assign your List to a String, and the necessary casting will be performed. You can then use a function that I wrote for this exact purpose to strip the brackets.
e.g.
String releaseVerFieldValueStr = releaseVerFieldValue
releaseVerFieldValueStr = stripBrackets(releaseVerFieldValueStr)
def stripBrackets(String str){
String retStr = str
if(str == null || str.length() < 2)
{
return str
}
if(retStr.substring(0,1).equals("[")){
retStr = retStr.substring(1)
}
if(retStr.substring(retStr.length()-1).equals("]")){
retStr = retStr.substring(0,retStr.length()-1)
}
return retStr
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.