Using issue.setComponentObjects([component.getGenericValue()]) to set Component in a subtask created in a post function. This does not work.

HI,

Iam trying to create a Subtask in a post function. WIth that writing a code to overwrite the Component value in Subtask . The code is

ProjectComponent component = projectComponentManager.findByComponentName(project.getId,"Confluence")

 issue.setComponentObjects([component.getGenericValue()])    

I do not see error in the log as well. But the old component is seen in the subtask and not the new one.

Iam using JIRA 6.4.14 and Script Runner 3.0.16.

1 answer

This widget could not be displayed.
Chris Fuller Atlassian Team Nov 11, 2016

GenericValue is a key-value representation of the database table row.  This is not a great way to represent data, so over the past several years we have been phasing them out of the API in favor of concrete, strongly-typed objects like ProjectComponent.  In places where we had to add a new method, the usual convention we have followed is to lead the old method alone (until recently; I think most of these finally changed in JIRA 7), and add a new one that speaks of "objects" instead.  For example, ProjectManager has these:

 

/**
     * Retrieve a single project by it's id.
     *
     * @param id the Project ID.
     * @return GenericValue representation of a Project.
     * @throws DataAccessException If any errors occur accessing the DB.
     * @deprecated please use {@link #getProjectObj}
     */
    @Deprecated
    GenericValue getProject(Long id) throws DataAccessException;

    /**
     * Retrieves a single {@link Project} by its id.
     *
     * @param id ID of the Project.
     * @return Project object or null if project with that id doesn't exist.
     * @throws DataAccessException If any errors occur accessing the DB.
     */
    Project getProjectObj(Long id) throws DataAccessException;

 

The former will give you a GenericValue while the latter will give you a Project.  The story is similar for project components and setting them for an issue.  MutableIssue has these:

 

/**
     * Sets the components for this Issue.
     * @param components the new components value
     *
     * @deprecated Use {@link #setComponentObjects(java.util.Collection)} instead. Since v5.0.
     */
    void setComponents(Collection<GenericValue> components);
    /**
     * Sets the components for this Issue.
     * @param components the new components value
     *
     * @since v5.0
     */
    void setComponentObjects(Collection<ProjectComponent> components);

 

So if you use the old setComponents then you have to give it GenericValue objects in the collection, but if you use setComponentObjects then you should just use ProjectComponent directly.

In short, just get rid of the getGenericValue() call.  You don't need it, as you just want to stick with the ProjectComponent that you already have.

 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 6 hours ago in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

26 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you