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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,556,538
Community Members
 
Community Events
184
Community Groups

error while creating custom field using script runner

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

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.
Jan 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events