Tyler Wright
Tyler Wright

Reputation: 825

Programmatically Creating a CustomField

I've been trying to figure out how to create a custom field in my Jira Plugin by using the Atlassian SDK, but I'm running into a couple of issues while wondering though the documentation and docs. Currently, I am able to create a custom field with the following code:

CustomField fieldType = customFieldManager.getCustomFieldObjectByName("Type of Work");
    CustomFieldSearcher fieldTypeSearcher = customFieldManager.getCustomFieldSearcher("com.atlassian.jira.plugin.system.customfieldtypes:select");
    if(fieldType == null) {
        List<String> issueTypes = new ArrayList<String>();
        issueTypes.add("Story");

        List<String> contextTypes = new ArrayList<String>();
        //contextTypes.add(GlobalIssueContext.GLOBAL_CONTEXT_STR);
        contextTypes.add("Global");

        /*Collection<IssueType> list = constantsManager.getAllIssueTypeObjects();
        for(IssueType issueType : list) {
            if(issueType.getName().equals("Story")) {
                issueTypes.add(issueType);
            }
        }*/

        /*if(issueTypes.size() == 0)
            throw new Exception("Greenhopper must be installed!");*/

        CustomFieldType selectFieldType = customFieldManager.getCustomFieldType("com.atlassian.jira.plugin.system.customfieldtypes:select");
        try {
            CustomField typeOfWorkField = customFieldManager.createCustomField("Type of Work", "Used to track a stories type of work", selectFieldType, fieldTypeSearcher, contextTypes, issueTypes);
            //typeOfWorkField.
        } catch (GenericEntityException e) {
            writeMe += e.toString();
        }
    }

My issue lies in setting the customFields context and issueTypes. I want it to work in the global context and in greenhoppers Story Issue. Can anyone help out? Also, once I get that setup, I would like to set up the default screen. Any ideas?

Upvotes: 4

Views: 2881

Answers (1)

Tyler Wright
Tyler Wright

Reputation: 825

Found the solution to my problem here

Upvotes: 2

Related Questions