You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Attempting to clone a field configuration scheme but running into a sql injection error. Script:
//Create a project objects (Source & Target)
Project jiraProjectSourceObj = projectManager.getProjectObjByName("SD_TEMPLATE")
Project jiraProjectTargetObj = projectManager.getProjectObjByName("SD_TEST")
//Define issue type scheme properties
def newIssueTypeSchemeObj
//Return a issue type scheme object
def ewIssueTypeSchemeObj = issueTypeScheme.getConfigScheme(jiraProjectTargetObj)
//Get issue types list
def issueTypesForScheme = issueTypeScheme.getIssueTypesForScheme(newIssueTypeSchemeObj)
List issueTypesList = new ArrayList(issueTypesForScheme)
//
def fieldConfigScheme = issueTypeScheme.getConfigScheme(jiraProjectSourceObj)
def configs = fieldConfigScheme.getConfigs()
def fieldConfigSchemeBuilder = new FieldConfigScheme.Builder(fieldConfigScheme)
fieldConfigSchemeBuilder.setName("sd_name")
fieldConfigSchemeBuilder.setDescription("sd_desc")
fieldConfigScheme = fieldConfigSchemeBuilder.toFieldConfigScheme()
//Get parameters
def configurableField = fieldConfigScheme.getField()
def contexts = fieldConfigScheme.getContexts()
def fieldConfig = fieldConfigScheme.getOneAndOnlyConfig()
fieldConfigSchemeManager.createFieldConfigScheme(fieldConfigScheme, contexts, issueTypesList, configurableField)
This is the error I receive:
|| Error: com.atlassian.jira.exception.DataAccessException: org.ofbiz.core.entity.GenericEntityException: while inserting: [GenericEntity:FieldConfigScheme][name,sd_name][description,sd_desc][id,26300][fieldid,issuetype] (SQL Exception while executing the following:INSERT INTO fieldconfigscheme (ID, configname, DESCRIPTION, FIELDID, CUSTOMFIELD) VALUES (?, ?, ?, ?, ?) (ORA-00001: unique constraint (JIRAMERGE.PK_FIELDCONFIGSCHEME) violated ))
What am I missing here? Thanks!
Hi there,
I think the main problem was some missing parts and syntax errors. Here is a cleaned version's code:
/**
* Atlassian Community answer
* <a href="https://community.atlassian.com/t5/Jira-Service-Desk-questions/Cloning-field-configuration-scheme-and-field-configuration-using/qaq-p/1449149" target="_blank">Cloning field configuration scheme (and field configuration) using groovy</a>
* @author Tamás Baglyas - https://github.com/tbaglyas
* @version 1.0
* @since 2020-08-05
*/
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.ProjectManager;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.issue.fields.config.manager.IssueTypeSchemeManager;
import com.atlassian.jira.issue.fields.config.FieldConfigScheme;
import com.atlassian.jira.issue.issuetype.IssueType;
import com.atlassian.jira.issue.fields.config.FieldConfigScheme.Builder;
import com.atlassian.jira.issue.fields.ConfigurableField;
import com.atlassian.jira.issue.context.JiraContextNode;
import com.atlassian.jira.issue.fields.config.FieldConfig;
import com.atlassian.jira.issue.fields.config.manager.FieldConfigSchemeManager;
ProjectManager projectManager = ComponentAccessor.getProjectManager();
//Create Source and Target project object
Project sourceProject = projectManager.getProjectObjByName("SD_TEMPLATE");
Project targetProject = projectManager.getProjectObjByName("SD_TEST");
//New issue types
IssueTypeSchemeManager issueTypeSchemeManager = ComponentAccessor.getIssueTypeSchemeManager();
FieldConfigScheme targetFieldConfigScheme = issueTypeSchemeManager.getConfigScheme(targetProject);
List<IssueType> issueTypes = (List<IssueType>)issueTypeSchemeManager.getIssueTypesForScheme(targetFieldConfigScheme);
//New FieldConfigScheme
FieldConfigScheme sourceFieldConfigScheme = issueTypeSchemeManager.getConfigScheme(sourceProject)
FieldConfigScheme.Builder fieldConfigSchemeBuilder = new FieldConfigScheme.Builder(sourceFieldConfigScheme);
fieldConfigSchemeBuilder.setName("sd_name");
fieldConfigSchemeBuilder.setDescription("sd_desc");
FieldConfigScheme newConfigScheme = fieldConfigSchemeBuilder.toFieldConfigScheme();
//Get parameters
ConfigurableField field = newConfigScheme.getField();
List<JiraContextNode> contexts = newConfigScheme.getContexts();
FieldConfigSchemeManager fieldConfigSchemeManager = ComponentAccessor.getFieldConfigSchemeManager();
FieldConfigScheme newFieldConfigScheme = fieldConfigSchemeManager.createFieldConfigScheme(newConfigScheme, contexts, issueTypes, field);
Nope, Dupliate key Primary, SQL error.
Please fix this as i would really love to put it in a for loop and give every project in my Jira instance its own field configuration and its own scheme programmatically like this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello.
There is way to generate random key but even in that case there is error contexts is empty
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.