Hey guys,
I’ve used the Scripted (Groovy) JMWE Post-Functions to do the following in a single workflow transition:
- Given a JQL filter name and a target project name, get the list of components missing from the target project and create them in the target project.
def String componentLeadName = "";
//Add the missing components to the delivery container
componentsToAdd.each{
if (it.componentLead != null){
componentLeadName = it.componentLead.username;
}
else{
componentLeadName = "";
}
//Add the component to the delivery project
ProjectComponent newComponent = null;
try {
newComponent = ComponentAccessor.projectComponentManager.create(it.name, it.description, componentLeadName, it.getAssigneeType(), deliveryContainerId);
componentsAdded.push(newComponent);
}catch (IllegalArgumentException exception){
//Add the name of the component if unable to create in delivery container
failedComponents.put(it.name, exception.message);
}
}
-
Given a JQL filter name and a target project name, get the list of versions missing from the target project and create them in the target project.
-
Given a JQL filter name, iterate through each issue and fill in empty fields (Descrition, Acceptance Criteria and Assignee)
if (issue.get("Customer Request Type")?.name == "Feature Migration to Jira 2.0"){
//Let the customer know that we're updating the issue fields
issue.setFieldValue("comment", "Updating empty fields on Features in JQL filter");
//Get the issues from the provided JQL filter
List <Issue> issues = jqlSearch("filter in (\"" + issue.get("Text Field 1") + "\")", 1000);
//Update empty Description, Acceptance Criteria and Assignee fields for Features
issue.setFieldValue("comment", "Updating the following fields for a Feature to 'TBD' if they are empty: Description, Acceptance Criteria and setting the Assignee to the value of SD_Resource Name field");
issues.each{
if (!it.issueType.name.equals("Feature")){
return;
}
if(it.description == null || it.description.isEmpty()){
it.setFieldValue("description", "TBD");
}
if(it.get("Acceptance Criteria") == null || it.get("Acceptance Criteria").isEmpty()){
it.setFieldValue("Acceptance Criteria", "TBD");
}
if(it.assignee == null){
it.setFieldValue("Assignee", issue.get("SD_Resource Name")?.name);
}
}
issue.setFieldValue("comment", "Finished updating empty Feature fields");
return;
}
I tested all the post-functions individually by using the Test Grovy Script option on each post-function. All of the post-functions work as expected when run that way. However, when I trigger the workflow transition from the ticket, I sometimes get the following behavior on the first go:
- Component/s show as created in the audit log, but don’t show up in the target project
- Field updates, especially the custom text field Acceptance Criteria and Assignee field are not updated to the specified value
When I trigger the workflow transition a second time I get the following behavior:
- Component/s show as created in the audit log and show up in the target project
- The field updates go through
As shown in the above code snippets, I’m using ProjectComponentManager’s create method for creating the components in a try-catch and I use setFieldValue method for updating the empty fields.
I’m stuck between it being a script issue and a delay in Jira after an action is made.
I appreciate any help in figuring out the problem.