Does anyone know how to retrieve the value of a custom field (String) in a custom script post function before the issue is actually created?
I am trying to add request participants based on the value of the custom field.
When I create a ticket with the LOB custom field value as CIO, it should add "alexandra" and "Service_Desk_Testing" as request participants.
However, when I created a ticket, it added "Service_Desk_Testing" and "Service_Desk_Testing2" as participants meaning it's not properly matching the value of the CIO field.
Does anyone know how I could retrieve the custom field value of the LOB field?
Thanks!
Here's what I have so far.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import java.util.ArrayList
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.index.IssueIndexManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def userManager = ComponentAccessor.getUserUtil()
def requestParticipantsField = customFieldManager.getCustomFieldObject("customfield_10001")
def lobField = customFieldManager.getCustomFieldObject("customfield_12345")
def issueManager = ComponentAccessor.getIssueManager()
def loggedInUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def getUsersAsArray = {
def users = ["Service_Desk_Testing"]
def lob = issue.getCustomFieldValue(lobField)
ArrayList<ApplicationUser> userList = new ArrayList<ApplicationUser>()
ArrayList<String> lobUserNames = new ArrayList<String>()
if (lob == 'CIO')
{ lobUserNames.add("alexandra") }
else {lobUserNames.add("Service_Desk_Testing2")}
lobUserNames.each {
def lobuser = userManager.getUserByName(it)
if (lobuser)
{ userList.add(lobuser)}
}//lobUserNames.each
users.each {
def user = userManager.getUserByName(it)
if(user)
{ userList.add(user) }
}//users.each
return userList
}//getUsersAsArray
MutableIssue myIssue = issue
ArrayList<ApplicationUser> applicationUsers = getUsersAsArray()
myIssue.setCustomFieldValue(requestParticipantsField, applicationUsers)
Shawn,
I think this is because Insight custom fields are not compatible with ScriptRunner behaviours. We have been working on implementing compatibility: https://productsupport.adaptavist.com/browse/SRJIRA-2563
I would suggest following that issue to see when the compatibility is released.
Regards,
Josh
Hi, I manage recently to use the insight fields in a behavior scriptrunner configuration.
I use the key of the object in the if statement instead of the string of the selected choice.
If the "required field" is set either to 'DD-166215' or 'DD-166253', then the text field will be set to visible and required.
Here is my example, hope it can guide you too.
it is set as a script on the field1 in behavior, ( not the initializer section)
def requiredField = getFieldByName('field1')
def textField = getFieldByName('field2')
def requiredValue = requiredField.getValue()
if (requiredValue.toString() == 'DD-166215' || requiredValue.toString() == 'DD-166253') {
textField.setRequired(true)
textField.setHidden(false)
} else {
textField.setRequired(false)
textField.setHidden(true)
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
one more thing,
To see the keys of the selected objects in the insight field.
Go to an issue that has these fields available on the screen, change the field on the issue. Go to the activity tab All to see all changes on the issue, there you will see the keys of the object you just changed.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Thanks for the example. I tried it out and i gor one issue. It seems like it doesnt react to the first selection. Let me try to describe it
I have a custom field mapped to and insight object type. No Default value and the above behaviour script on it. When I select the first time theres no reaction. As soon as a I make the second selection The behaviour starts reacting.
Does it make sense?
Any ideas
Regards Michael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, I have 3 fields in my form.
I hide the last two.
Configured behaviour for the first field "Projects".
Script part.
def projectcf = getFieldById("customfield_13107")
def juricf = getFieldById("customfield_13108")
def rolecf = getFieldById("customfield_13109")
juricf.setHidden(true)
rolecf.setHidden(true)
def project = projectcf.getValue()
if (project) {
juricf.setHidden(false)
}
Then I added configuration for "Jurisdictions" field.
Script part.
def juricf = getFieldById("customfield_13108")
def rolecf = getFieldById("customfield_13109")
def jurisdiction = juricf.getValue()
if (jurisdiction) {
rolecf.setHidden(false)
}
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.