Hi @Ashok Barik is it ok to set the "Money spent" value only via transition screen or you need to edit it via inline edit on issue detail?
In case you can do it via transition screen (I suggest this solution), you can use scripted postfunction. In case you need to do it via inline edit, you need to use Listener which listens to Issue Updated event.
I think you can use following logic
Let me know, if you need more information
Hi @Martin Bayer [MoroSystems, s.r.o.] I need to edit it via inline edit on issue detail.
I used a field script in the script runner, but the value for the Total spent field was incorrect. Could you please send me the script for this, if it is possible in Listener?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ashok Barik sure, more information about Listeners are here:
https://docs.adaptavist.com/sr4js/latest/features/listeners/custom-listener
Adaptavist also prepared some code snippets and there is one with listener...
Let me know if you need more help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Martin Bayer [MoroSystems, s.r.o.] Thanks a lot for providing me with all details.
I used this script in the Script Runner field but it didn't work, can it work in Listener?
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser
Issue issueKey = issue
def id=issueKey.getId()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def cff = customFieldManager.getCustomFieldObjectByName("Money Spent")
def b = Integer.parseInt((issue.getCustomFieldValue(cff) ?: 0).toString().replaceAll(~/[.].*/, ""))
def changeHistoryManager = com.atlassian.jira.component.ComponentAccessor.getChangeHistoryManager()
def old = changeHistoryManager.getChangeItemsForField(issue, 'Total Spent')
def d = 0;
if (old != null) {
Integer sum = b + d
return sum
}
else {
def cf = customFieldManager.getCustomFieldObjectByName("Total Spent")
def n = Integer.parseInt((issue.getCustomFieldValue(cf) ?: 0).toString().replaceAll(~/[.].*/, ""))
Integer sum = n + b
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Martin Bayer [MoroSystems, s.r.o.]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ashok Barik , followint script is working for me :)
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
def issue = event.issue
def loggedInUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def change = event.changeLog.getRelated("ChildChangeItem")?.find { it.field == "Money spent" }
// a field other than the Account field updated, nothing to do here
if (!change) {
return
}
def customFieldManager = ComponentAccessor.customFieldManager
def moneySpentField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Money spent" }
def totalSpentField = customFieldManager.getCustomFieldObjects(issue).find { it.name == "Total spent" }
def moneySpent = issue.getCustomFieldValue(moneySpentField) as Double
moneySpent = moneySpent ?: 0
def totalSpent = issue.getCustomFieldValue(totalSpentField) as Double
totalSpent = totalSpent ?: 0
totalSpentField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(totalSpentField), totalSpent + moneySpent), new DefaultIssueChangeHolder())
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.