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

Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2019

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
Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2019

@Jaron Stevenson  and @Leo , thank you both of you, for your time !  

I will follow your instructions and reply back the results. 

Gratitude. 

Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2019

@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 

Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2019

One point I didn't mentioned. 

This operattions are for Requests and not Issues. 

 

Kind Regards 

Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 19, 2019

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
Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2019

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 

Jaron Stevenson November 19, 2019

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
Maikes
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2019

@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
Jaron Stevenson November 20, 2019

Awesome! Glad you were able to find a solution!

1 vote
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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 

0 votes
Jaron Stevenson November 18, 2019

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 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
Jaron Stevenson November 19, 2019

Ah cool, learned something new!

Suggest an answer

Log in or Sign up to answer