Hi,
I want to create a script field which calculates a value and depending on the value it should update another custom field. So far I have created following script:
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.issue.customfields.option.Options
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import java.lang.Math
IssueService issueService = ComponentAccessor.getComponent(IssueService)
IssueInputParameters issueInputParameters = issueService.newIssueInputParameters()
def customFieldManager = ComponentAccessor.getComponent(CustomFieldManager)
def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def user = ComponentAccessor.getJiraAuthenticationContext().loggedInUser
def A = getCustomFieldValue("Planned Project hours of work")
def B = getCustomFieldValue("Actual Project hours of work + ETC (hours)")
def result = (B-A)/A
def percent = result * 100
return (Math.floor(percent*100)/100 + "%")
def KPI_Project_Work = getCustomFieldValue("KPI: Project Work")
Options options = optionsManager.getOptions(KPI_Project_Work.getConfigurationSchemes().first().getOneAndOnlyConfig())
if (percent < 10)
{
def selectedOptions = options.findAll {
it.value == "Green"
}.collect {
it.optionId.toString()
}
}
I already get the value of "percent", but when I try to update the field value "KPI_Project_Work", just nothing happens. Can anyone help me out?
Best Regards
Robert
Are you able to update the CF value in the scripted console?
Look at this documentation, it may help
https://library.adaptavist.com/entity/update-the-value-of-custom-fields-through-the-script-console
I think that when you put the "return" your code execution ends.
So, If you want to update or do any other operation, just do it before you return a value.
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.