Hi Community, there is an existing Behaviour script that I need to modify. The current script working fine. If the number is 10000 or less it add the user1 to a user field but if the number is greater than 10000 it add user2 to the user field. There is an additional requirement now. If the number is 5000 or less add reporter to user field, if number is more than 5000 and 1000 or less add user1 to user field greater than 10000 should be the same. Here is an example:
5000 or less = Issue Reporter
Greater than 5000 and less than 1000 = User1
Greater than 10000 = User2
How can modify and achieve the requirement?
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def userFormField = getFieldById('customfield_11305')
def textFormField = getFieldById('customfield_11306')
Integer number = textFormField.getValue() as Integer
String user = number > 10000 ? 'user2' : 'user1'
userFormField.setFormValue(user)
Thank you,
Hi Swapnil,
I understand your use-case and I think I have a script that almost accomplishes this, but could you clarify?
Do you want the sum of ALL issues in the project that have an issue type of "Sub-story", regardless if they are connected to the same Story?
Or
Do you want the sum of all connected "Sub-story" issues for each Story?
Hi Joshua,
Thank you for looking into this.
I would require the second example -
"Do you want the sum of all connected "Sub-story" issues for each Story?
Thanks again for your help.
Best Regards,
Swapnil Tiwari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swapnil,
I created the following script to be used in a scripted field. It gets all of the links from the Story and checks to see if the are of type "Sub-story". If there are "Sub-story" linked issues, it will get the custom field value from "Technical Points" on each issue. It will return the sum of all of the Sub-story issues linked to the Story.
import com.atlassian.jira.component.ComponentAccessor
if (issue.getIssueType().name == "Story") { // only calculate this for Story Issue Types
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def pointSum = 0
issueLinkManager.getOutwardLinks(issue.id).each {issueLink -> // go through all issues linked off of the Story
def linkedIssue = issueLink.getDestinationObject()
if (linkedIssue.getIssueType().name == "Sub-story") {
def technicalPointsField = customFieldManager.getCustomFieldObjectByName("Technical Points")
pointSum += linkedIssue.getCustomFieldValue(technicalPointsField)?:0
}
}
return pointSum
}
Image of it working:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should also make sure that the Template for the Scripted Field is set to "Number Field" and that the Searcher is set to "Number Searcher".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Joshua,
The query is giving me the error.
It says "The variable issue is not declared"
Please help
Thank you,
Swapnil Tiwari
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Swapnill.
That is an inline error, not a compilation error. The script could be working at compilation time. Could you save the script regardless and try to see if the script works?
Cheers!
Dyelamos
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.
Hi Swapnil,
You are using this code inside of a scripted field, correct? Which version of ScriptRunner are you using?
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.