Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=Step+3%3A+Creating+a+Custom+Field+Descriptor+-+15486516
widthauto

Project Picker CF

Let's say you need to provide support for a certain custom field. Power Scripts™ for Jira does offer support for the project picker CF but for educational purposes, let's see how you could add the support if it didn't.

...

Code Block
firstline1
titleBundleActivator.java
linenumberstrue
@Override
public void doAtLaunch() {
    super.doAtLaunch();

    //register the routinefunction
    RoutineRegistryFunctionRegistry.register(new ReverseStringRoutineReverseStringFunction("myReverseString"));

    //register the CF descriptor
    customFieldDescriptorRegistry.register("com.atlassian.jira.plugin.system.customfieldtypes:project", //this is the real key of the CF
            new AbstractCustomFieldDescriptorFactory(
                    "example.project.cfdf", //internal identification. Must be unique in the SIL system
                    "Project Key to String", //short description, followed by a longer one
                    "Extract the project key using GenericValue or project") {

				// Descriptors are created when needed, and some of them might be contextual. This is why you register here a creator of a
			    // descriptor and not the real descriptor
			    @Override
                public FieldDescriptor createDescriptor(Issue issue, CustomField cf) {
                    return new ProjectCFDescriptor(projectManager);
                }
            }
    );
}

@Override
public void doAtStop() {
    //first, make sure that super is called, even if it has an exception here
    try {
        //unregister the routinefunction
        RoutineRegistryFunctionRegistry.unregister("myReverseString");
        
        //unregister the CF descriptor
        customFieldDescriptorRegistry.unregister("com.atlassian.jira.plugin.system.customfieldtypes:project");  //this is the real key of the CF
    } catch(Exception e) {
        LOG.error("Failed to unregister!", e);
    }
    
    super.doAtStop();
}

...