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.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.