I write a groovy script in post-function to calculate the value of field "Effort Split" in Epic based on the Stories (Sum of all "Effort Split" values in Stories), and now i can get the sum value and show it in Epic issue. But these change cannot be updated in history of Epic issue.
Could you please give me some suggestions? If there is some groovy sentence can achieve this?
My code like below:
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()
String issuekey=issue.toString()
IssueLinkManager issueLinkManager = componentManager.getIssueLinkManager()
List list = issueLinkManager.getOutwardLinks(componentManager.getIssueManager().getIssueByCurrentKey(issuekey).id)
Map<String, String> effortSplitMap = new HashMap<String, String>();
for(i=0;i<list.size();i++){
String effortSplit = list[i].destinationObject.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Effort Split'))
List effortSplitList = new ArrayList()
effortSplitList = effortSplit.split("\r\n")
for(j=0;j<effortSplitList.size();j++){
if(effortSplitMap.get(effortSplitList[j].split("&")[0]))
{ effortSplitMap.put(effortSplitList[j].split("&")[0].trim(),(Integer.parseInt(effortSplitList[j].split("&")[1].trim()) + Integer.parseInt(effortSplitMap.get(effortSplitList[j].split("&")[0]))).toString()) }
else
{ effortSplitMap.put(effortSplitList[j].split("&")[0].trim(),(Integer.parseInt(effortSplitList[j].split("&")[1].trim())).toString()) }
}
}
StringBuffer stringBuffer = new StringBuffer()
stringBuffer.append("HLR_DEV")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("HLR_DEV"))
stringBuffer.append("\r\n")
stringBuffer.append("HSS_DEV")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("HSS_DEV"))
stringBuffer.append("\r\n")
stringBuffer.append("LTE_DEV")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("LTE_DEV"))
stringBuffer.append("\r\n")
stringBuffer.append("DB_DEV")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("DB_DEV"))
stringBuffer.append("\r\n")
stringBuffer.append("HLR_FT")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("HLR_FT"))
stringBuffer.append("\r\n")
stringBuffer.append("HSS_FT")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("HSS_FT"))
stringBuffer.append("\r\n")
stringBuffer.append("LTE_FT")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("LTE_FT"))
stringBuffer.append("\r\n")
stringBuffer.append("DB_FT")
stringBuffer.append("&")
stringBuffer.append(effortSplitMap.get("DB_FT"))
issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Effort Split'),stringBuffer.toString())
DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();
def cf_object=customFieldManager.getCustomFieldObjectByName('Effort Split')
cf_object.updateValue(null, issue, new ModifiedValue(null, issue.getCustomFieldValue(cf_object)), issueChangeHolder);
Hello,
Now the Epic effort value can be updated based on the story effort via my code, but this update cannot be displayed in the history log of issue. So what we should do if i want this change can be displayed in the History activity.
Thanks and Regards
If you want it displayed in the changelog you should probably use a real field, and update it in a listener.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don;t think you want to store in the change history the value of a calculated field. What's the purpose, to see how the story effort changed over time?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
Is there anyone can help me on this issue, how i can update my change history in JIRA issue when the issue's field value is calculated by its linked issue.
Thanks and Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.link.IssueLinkManager import com.atlassian.jira.ComponentManager import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.util.DefaultIssueChangeHolder ComponentManager componentManager = ComponentManager.getInstance() CustomFieldManager customFieldManager = componentManager.getCustomFieldManager() String issuekey=issue.toString() IssueLinkManager issueLinkManager = componentManager.getIssueLinkManager() List list = issueLinkManager.getOutwardLinks(componentManager.getIssueManager().getIssueByCurrentKey(issuekey).id) Map<String, String> effortSplitMap = new HashMap<String, String>(); for(i=0;i<list.size();i++){ String effortSplit = list[i].destinationObject.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Effort Split')) List effortSplitList = new ArrayList() effortSplitList = effortSplit.split("\r\n") for(j=0;j<effortSplitList.size();j++){ if(effortSplitMap.get(effortSplitList[j].split("&")[0])) { effortSplitMap.put(effortSplitList[j].split("&")[0].trim(),(Integer.parseInt(effortSplitList[j].split("&")[1].trim()) + Integer.parseInt(effortSplitMap.get(effortSplitList[j].split("&")[0]))).toString()) } else { effortSplitMap.put(effortSplitList[j].split("&")[0].trim(),(Integer.parseInt(effortSplitList[j].split("&")[1].trim())).toString()) } } } StringBuffer stringBuffer = new StringBuffer() stringBuffer.append("HLR_DEV") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("HLR_DEV")) stringBuffer.append("\r\n") stringBuffer.append("HSS_DEV") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("HSS_DEV")) stringBuffer.append("\r\n") stringBuffer.append("LTE_DEV") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("LTE_DEV")) stringBuffer.append("\r\n") stringBuffer.append("DB_DEV") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("DB_DEV")) stringBuffer.append("\r\n") stringBuffer.append("HLR_FT") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("HLR_FT")) stringBuffer.append("\r\n") stringBuffer.append("HSS_FT") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("HSS_FT")) stringBuffer.append("\r\n") stringBuffer.append("LTE_FT") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("LTE_FT")) stringBuffer.append("\r\n") stringBuffer.append("DB_FT") stringBuffer.append("&") stringBuffer.append(effortSplitMap.get("DB_FT")) issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName('Effort Split'),stringBuffer.toString()) DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder(); def cf_object=customFieldManager.getCustomFieldObjectByName('Effort Split') cf_object.updateValue(null, issue, new ModifiedValue(null, issue.getCustomFieldValue(cf_object)), issueChangeHolder);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you format your code using the {code} macro so that it's readable. Please add some logging so you know that it's being executed at all first, eg log the value that it's going to set.
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.