Dear Collegues from Atlassian Community,
I need to know if there is possible to automatically populate multiple custom field based on a previous fields value ?
For example:
x = Sim;
Autopopulate:
y = z ;
h = OOO;
I'm using Script Runner in Jira.
Can someone help me?
Thank you for your time.
Kind Regards
@Jaron Stevenson and @Leo , thank you both of you, for your time !
I will follow your instructions and reply back the results.
Gratitude.
@Leo and @Jaron Stevenson , I decided to fo throw a simpler step,
If the Field [Priority] == "Other"
-> The field [Priority Other], changes from hidden to Visible;
I created a behaviour with the following code, on server side, in the variable [Priority]:
{
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def regressionIssueField = getFieldById(getFieldChanged())
def regressedVersionField = getFieldByName("Priority [Other]")
String regressionIssueValue = regressionIssueField.getValue()
if (regressionIssueValue == "Other") {
regressedVersionField.setRequired(true)
regressedVersionField.setHidden(false)
} else {
regressedVersionField.setRequired(false)
regressedVersionField.setHidden(true)
}
}
Fot this I followed the following tutorials, but unfortunatly I couldn't get the final result as expected:
I ask for your support one more time.
Kind Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One point I didn't mentioned.
This operattions are for Requests and not Issues.
Kind Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I'm right, you should use below method for getting value of field in behaviours(is quite different from post-function and listener scripts)
String regressionIssueValue = regressionIssueField.getFormValue()
maybe you can include "as String" for type casting
String regressionIssueValue = regressionIssueField.getValue() as String
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @Leo , thank you for your time, but is not working in Customer Portal ...
This operations are working for issues but not for requests in the Customer Portal.
Do you have any idea ?
Kind Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, I don't have much experience working with Jira Service Desk. However, I did find these two ScriptRunner articles about using ScriptRunner to work with ServiceDesk, maybe they will be helpful to you:
Behaviours with Service Desk - Describes how to create Behaviours specifically for the customer portal. Which is exactly what you're doing I believe.
Scripting Service Desk - General resource for writing scripts for Service Desk.
Hope this helps!
-Jaron
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Jaron Stevenson and @Leo . Issue Resolved.
You just need in Mapping Section inside Behaviour section you just need to select this options [Then Add Mapping]:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Awesome! Glad you were able to find a solution!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Maikes,
Along with @Jaron Stevenson 's answer would like to mine as well
I would suggest Behaviour feature in scriptrunner. put the below code in Behaviour field for "X" so whenever X is getting updated with your validation you can update y and h as well
I'm adding sample code for your reference
def x = getFieldByName("x") //or you can use getFieldById("customfield_XXXXX")
method as well
def y = getFieldByName("y")
def h = getFieldByName("h")
def xValue = x.getFormValue() as String
if(xValue == "sim"){
y.setFormValue("z")
h.setFormValue("OOO")
}
BR,
Leo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Maikes,
Would this be an operation you would want to run when transitioning between statuses in the workflow, or would it be on update of the issue?
For the former, you could add a post function to the transition that would update the custom fields appropriately (you may need an add-on such as Workflow Enhancer for Jira).
For the latter, you could use ScriptRunner to create a Custom Listener that would run on the Issue Updated event (see image).
If you need help with the body of the code, these may help: https://scriptrunner.adaptavist.com/latest/jira/recipes/workflow/postfunctions/set-issue-attributes.html, https://scriptrunner.adaptavist.com/latest/jira/listeners.html
The first is intended for custom post functions, but I believe the code for the listener would be similar. You would just have to get which issue you are working with from the event, as described in the second link under the custom listeners section.
e.g.
// set the issue from the event to a variable
def issue = event.issue
// Get the custom field object by it's name
def textCf = customFieldManager.getCustomFieldObjectByName("TextFieldA")
// Set the value of the custom field on the issue the event pertains to
issue.setCustomFieldValue(textCf, "Your text value")
-Jaron
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I guess this script will work on post-function but to update field from listener you should use changeHolder
def myIssue = event.issue
cf.updateValue(null, myIssue, new ModifiedValue(myIssue.getCustomFieldValue(cf),value), changeHolder)
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.
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.