Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to auto populate multiple custom field based on a previous fields value!?

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 

 

3 answers

1 accepted

0 votes
Answer accepted

@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 

One point I didn't mentioned. 

This operattions are for Requests and not Issues. 

 

Kind Regards 

Leo Community Leader Nov 19, 2019 • edited

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

 

Like Jaron Stevenson likes this

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 

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

Like # people like this

@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]: 

1.png

Like # people like this

Awesome! Glad you were able to find a solution!

1 vote
Leo Community Leader Nov 18, 2019

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 

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).

Capture.PNG

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

Leo Community Leader Nov 18, 2019

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)

Like Jaron Stevenson likes this

Ah cool, learned something new!

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you