Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

error while creating custom field using script runner

Vedant Kulkarni January 8, 2018

I want to create select List custom field using script runner and field will be having data from database but as I am new in this I am just creating select list custom field first. But I am facing following error . Am I following correct way to create custom field using script runner? 

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.context.JiraContextNode
import com.atlassian.jira.issue.context.GlobalIssueContext
import com.atlassian.jira.issue.issuetype.IssueType;

createCF()
CustomField createCF()
{
def cfManager=ComponentAccessor.getCustomFieldManager();
def selectList=cfManager.getCustomFieldType("com.atlassian.jira.issue.customfields.impl.SelectCFType");
def selectListSearcher=cfManager.getCustomFieldSearcher("com.atlassian.jira.issue.customfields.impl.SelectCFType");

List <JiraContextNode> context= new ArrayList<JiraContextNode>();
context.add(GlobalIssueContext.getInstance());

def bugIssueType = ComponentAccessor.getConstantsManager().allIssueTypeObjects.find {it.name == "Bug"}
List<IssueType> issueTypes = new ArrayList<IssueType>()
issueTypes.add(bugIssueType)



return cfManager.createCustomField("SelectList CF","Demo purpose",
selectList,selectListSearcher, context, issueTypes )

}

 

error:

2018-01-08 14:00:46,898 ERROR [runner.ScriptFieldPreviewRunner]: ************************************************************************************* 2018-01-08 14:00:46,899 ERROR [runner.ScriptFieldPreviewRunner]: Script field preview failed for field that has not yet been created java.lang.IllegalArgumentException: Invalid module key specified: at com.atlassian.plugin.ModuleCompleteKey.<init>(ModuleCompleteKey.java:49) at com.atlassian.plugin.ModuleCompleteKey.<init>(ModuleCompleteKey.java:29) at com.atlassian.plugin.manager.ProductPluginAccessorBase.getEnabledPluginModule(ProductPluginAccessorBase.java:180) at com.atlassian.plugin.manager.ForwardingPluginAccessor.getEnabledPluginModule(ForwardingPluginAccessor.java:54) at com.atlassian.plugin.manager.EnabledModuleCachingPluginAccessor.getEnabledPluginModule(EnabledModuleCachingPluginAccessor.java:39) at com.atlassian.plugin.manager.ForwardingPluginAccessor.getEnabledPluginModule(ForwardingPluginAccessor.java:54) at com.atlassian.plugin.manager.ProductPluginAccessor.getEnabledPluginModule(ProductPluginAccessor.java:19) at com.atlassian.extension.plugins.ExtensionAccessingPluginAccessor.getEnabledPluginModule(ExtensionAccessingPluginAccessor.java:169) at com.atlassian.jira.plugin.customfield.CustomFieldTypeModuleDescriptorsImpl.getCustomFieldType(CustomFieldTypeModuleDescriptorsImpl.java:51) at com.atlassian.jira.issue.managers.CachingCustomFieldManager.getCustomFieldType(CachingCustomFieldManager.java:204) at com.atlassian.jira.issue.CustomFieldManager$getCustomFieldType.call(Unknown Source) at Script161.createCF(Script161.groovy:11) at Script161.run(Script161.groovy:7)

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Joanna Choules
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.
January 26, 2018

Hi Vedant,

Where are you running this script? By the look of the error message it seems you're using the preview functionality of the Script Fields form, but this is not the sort of code that you would want to put in a script field, since it will be run (thus creating a custom field) every time the script field is viewed (which will probably be a lot of times). It would help us to assist you if you could describe the intended purpose of the script.

Even without knowing what the script is for, one problem I can see with it is that you are using the wrong string for the custom field type key. Instead of "com.atlassian.jira.issue.customfields.impl.SelectCFType", you should use "com.atlassian.jira.plugin.system.customfieldtypes:select". You can find information on how to construct the keys for various field types in the documentation for CustomFieldManager.

Thanks,

J

TAGS
AUG Leaders

Atlassian Community Events