This may seem weird but I am using a scripted field to get the sum total of (budget) - (spend to-date) - (accrual) to the scripted field (Remaining Budget). The problem is we're using Portfolio and Portfolio wont display scripted fields. So I think that I need to create a listener that will update a number custom field with the results from the scripted field (Remaining Budget). Can someone please help.
Thanks.
Hi Eric
Considering that you don't have much experience with Groovy scripting, this webinar might be useful to you: https://www.adaptavist.com/webinars/groovy-scripting-for-scriptrunner/
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.
thanks. I watched some of it and it explains a few things that I didnt know before.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is good to hear :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Eric Sebian
Please check https://library.adaptavist.com
There you can find a lot of example and working scripts that you can easily modify. I did it few times and save a lot of time :)
Regards,
Sebastian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I checked there, but unfortunately I'm not familiar with groovy scripting but I'll try. Thanks for the link.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below is what I'm using so far to calculate the scripted field. What I need now is a way to take that calculated value of the scripted field and copy it to a custom field. I'd like to do all of this within the scripted field Is it possible? :
import com.atlassian.jira.component.ComponentAccessor
def aval = getCustomFieldValue("Budget")
def bval = getCustomFieldValue("Accruals")
def cval = getCustomFieldValue("Spend to-date")
// check both fields contain valid numeric values and if not set them to 0
if (aval == null) {
aval = 0
}
if (bval == null) {
bval = 0
}
if (aval != null && bval != null){
return cval - bval - aval
} else {
// return to some code to indicate a null value in one of the fields
return 0
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you need to set field value you should use
issue.setCustomFieldValue(field, value)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Sebastian. I dont need to set it. I need to copy the value from the scripted field to another custom field on the same issue.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Copying value from one field to second field is basically setting second field with value from first field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So I couldn't figure out how to do it all in the scripted field so I left the scripted field as is and added a listener. I wish that I could have figured how the do it all in the one scripted field, but this is working. If someone has a better way, I'm all ears.
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName("Remaining Budget(hidden)")
def cFieldValue = issue.getCustomFieldValue(cField)
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "Remaining Budget"}
def changeHolder = new DefaultIssueChangeHolder()
tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), cFieldValue as Double),changeHolder)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Eric Sebian Did you ever figure out how to update another script field from within a script field ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
actually i just got it to work I think ..
i created a new mutableissue
MutableIssue mutableIssue = (issueManager.getIssueByCurrentKey(issue.getKey()))
and used that to update the other custom field:
mutableIssue.setCustomFieldValue(group, yellow)
issueManager.updateIssue(loggedInUser, mutableIssue, EventDispatchOption.DO_NOT_DISPATCH, false)
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.