Hello everyone,
I am really stuck here with problem of setting a value to compoments. Description of what I am doing and what I would like to get.
1. We have some EPIC links which have set components, labels etc.
2. When we create Issue which is linked to some epic we would like to have a newly created Issue with same information in components. Instead of chosing it manually.
so what we did, was we created a post function which looks like this:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import groovy.transform.Field;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
def log = Logger.getLogger("com.acme.CreateSubtask");
log.setLevel(Level.DEBUG);
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
Issue epic = (Issue)issue.getCustomFieldValue(epicLink);
if(epic)
{
issue.setComponent(epic.getComponents());
}
after debugging everything, it works. "log.debug issue.getComponents();" will show that all components was set by "issue.setComponent(epic.getComponents());" but on the site of issue. Value in field "component/s" is "none"
Can you please help me with this? I tried "issue.stored" or sth to update it, but nothing worked.
Hi Stanislav,
I suppose you should create new IssueInputParameters using IssueService, then invoke setComponentIds(yourComponentIds), then issueService.validateUpdate() and then issueService.update().
Isn't there a different way? I like the way that you add some post function script that should evaluate within the creating issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, it's the same way, just implement the logic described above instead of issue.setComponent(epic.getComponents()). Because in your case you just change the issue object without real updating the issue.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please write it down for me? I am having trouble with it, can't really see how to declare it, eventhough I am looking to Jira docs about it.
I would really appreciate it. Thank you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you at least advise me how do I get componentsID? I mean I am getting values from epic into Issue, but that issue cant be parsed into IssueInputParameters
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You already have Collection<ProjectComponent> from epic.getComponents() so you can just collect ids:
Long[] componentIds = epic.getComponents().stream().map(ProjectComponent::getId).toArray(Long[]::new);
issueInputParameters.setComponentIds(componentIds);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, that's where I get into trouble, collecting IDs. Your code doesn't work, it seems that stream(), does not have method of map.
Could you please explain what is that "map", "stream" or just fix the code?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"map", "stream" are java 8 Stream API.
Ok, try old style:
Collection<ProjectComponent> components = epic.getComponents();
List<Long> componentIds = new ArrayList<>(components.size());
for (ProjectComponent component : components) {
componentIds.add(component.getId());
}
issueInputParameters.setComponentIds(componentIds.toArray(new Long[0]));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No compilation error, but when I executed:
2017-08-15 09:49:57,487 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: IS-4111, actionId: 1, file: <inline script> groovy.lang.MissingPropertyException: No such property: issueInputParameters for class: Script511 at Script511.run(Script511.groovy:39)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Full script:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.IssueInputParameters;
import com.atlassian.jira.bc.issue.IssueService;
import com.atlassian.jira.bc.project.component.ProjectComponent;
import groovy.transform.Field;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
def log = Logger.getLogger("com.acme.CreateSubtask");
log.setLevel(Level.DEBUG);
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField epicLink = customFieldManager.getCustomFieldObjectByName('Epic Link');
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
Issue epic= (Issue)issue.getCustomFieldValue(epicLink);
if(epic)
{
//Your part
Collection<ProjectComponent> components = epic.getComponents();
List<Long> componentIds = new ArrayList<>(components.size());
for (ProjectComponent component : components) {
componentIds.add(component.getId());
}
issueInputParameters.setComponentIds(componentIds.toArray(new Long[0]));
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Aleksandr,
forgive me my hastiness, I didn't thought this through and forgot on validate / update. Everything now works as we want. I am really grateful for your support.
You are awesome!
Cheers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Stanislav,
nice to hear that it works well. Glad to help you!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.