Hi!!!!.
We have the following script connected in a post function. In the subtask. The script adds the value of the subtask to the main task. And it works. The problem comes that every time the issue goes to a previous state and goes through this posfunction, the value is added again. Can you help us?
import org.apache.log4j.Category
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.util.IssueChangeHolder
import com.opensymphony.workflow.InvalidInputException
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.util.ImportUtils;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
def issueManager = ComponentAccessor.getIssueManager();
def parentissue = issue.getParentObject()
MutableIssue parent = issue.getParentObject() as MutableIssue
//Llamada al customfield Total paid
String field_name = "Total paid";
//Si la Task padre no es Sales Order o Purchase entonces vuelve
if(parentissue.getIssueType().getName() != "Sales Order") {
if(parentissue.getIssueType().getName() != "Purchase") {
if(parentissue.getIssueType().getName() != "Test")
return;}}
//Calculamos la suma llamando al customfield
CustomField customField = customFieldManager.getCustomFieldObjectByName(field_name);
String field_name2 = "Total paid";
CustomField customField2 = customFieldManager.getCustomFieldObjectByName(field_name2);
//Primer calculo: llamamos al total amount de la issue padre
def parent_amount = parentissue.getCustomFieldValue(customField2) as Double
//Segundo calculo: llamamos al total amount de la subtask
def subtask_amount = issue.getCustomFieldValue(customField) as Double
//Realizamos la suma entre el primer c??lculo y el segundo c??lculo indicando que, si el valor de issue padre es nulo, entonces tome directamente el valor de subtask
def totalPaid
if(parent_amount != null) {
totalPaid = (Double) parent_amount + subtask_amount
} else {
totalPaid = subtask_amount
}
//Finalmente guardamos el valor actualizando el campo de la issue padre
parent.setCustomFieldValue(customField, String.valueOf(totalPaid));
IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
customField2.updateValue(null, parent, new ModifiedValue(parent.getCustomFieldValue(customField2), totalPaid), changeHolder);
You'll need to add some "if" code to the top of the script - somehow do "if already added this one up, exit without adding it again"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, I don't know how your data works or how you want to detect when the data should or should not be updated - that logic is up to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.