Copying custom field value to another custom field depending on the third custom field value

Hi,

Below is my requirement,

I have below fields

1.SG1 date (date field)

2.SG2 date (date field)

3.SG3 date (date field)

4. Next Gate (drop down with values 1. SG1 related

                                                          2.SG2 related

                                                          3.SG3 related

5.Next Gate Due( date field)

 

Now "Next Gate Due" custom field should automatically copy values from either SG1 date, SG2 date or SG3 date custom fields depending on Next Gate value selected.

Example scenario:

Assume custom fields value are set as below,

SG1 date : 12/8/2015

SG2 date : 12/15/2015

SG3 date : 12/17/2015

Next Gate : SG2 related

Next Gate Due:

 

Now Next Gate Due custom field should display the date depending on the Next gate custom field value. In above scenario it should automatically display 12/15/2015 as SG2 related value is selected in Next Gate custom field.

How can we achieve this. Is there a script,? if yes please share the script to achieve this.

 

Thanks in advance,

Nandeesh

 

3 answers

1 accepted

0 vote

Hi Nandeesh,

 

please, add the following code to your behaviour, associated to "Next Gate" field.

FormField nextgateff = getFieldById(getFieldChanged())
FormField sg1 = getFieldByName("SG1 date")
FormField sg2 = getFieldByName("SG2 date")
FormField sg3 = getFieldByName("SG3 date")
FormField nextGateDue = getFieldByName("Next Gate Due")
def nextGateValue = nextgateff.getValue()
if(nextGateValue!=null && !"".equals(nextGateValue)){
    if(nextGateValue.startsWith("SG1")){
        nextGateDue.setFormValue(sg1.getFormValue())
    }
    if(nextGateValue.startsWith("SG2")){
        nextGateDue.setFormValue(sg2.getFormValue())
    }
    if(nextGateValue.startsWith("SG3")){
        nextGateDue.setFormValue(sg3.getFormValue())
    }
}

Hope it helps,

Fabio

hi Fabio, this Script does not work :(

Hi Nadeeesh, I tried it on my local instance and it worked. Just to be sure, did you add this script to a behaviour associated to your project/issue type and related to Next Gate field? Can you provide me more information about your issue? Regards, Fabio

Hi Fabio, Yes i added this script to a behaviour associated to my project/issue type and related to Next Gate field. Did you try SG1, SG2, SG3 and Next Gate Due with date fields? When i give date in SG1, SG2, SG3 and select any value in Next Gate field, Next Gate Due is not populating any data.

Hi Nadeesh, yes, I created custom fields with the provided format. Please check custom fields name. In my script SG1 is "SG1 date", SG2 is "SG2 date" and so on. If your custom fields are just SG1, SG2.. please remove date from my script ... ... FormField sg1 = getFieldByName("SG1") FormField sg2 = getFieldByName("SG2") FormField sg3 = getFieldByName("SG3") ...

Hi Fabio, in my instance also its same "SG1 Date" and so on. Still not working :( Next Gate Due is not populating any data.

Hi Nandeesh, please take care about your custom fields name. Script is case sensitive so if you use "SG! Date", script should be : ... FormField sg1 = getFieldByName("SG1 Date") ...

Hi Fabio, Yes i have taken care of this. Below is the script, Not sure why it is not working :( FormField nextgateff = getFieldById(getFieldChanged()) FormField sg1 = getFieldByName("SG1 Date") FormField sg2 = getFieldByName("SG2 Date") FormField sg3 = getFieldByName("SG3 Date") FormField nextGateDue = getFieldByName("Next Gate Due") def nextGateValue = nextgateff.getValue() if(nextGateValue!=null && !"".equals(nextGateValue)){ if(nextGateValue.startsWith("SG1")){ nextGateDue.setFormValue(sg1.getFormValue()) } if(nextGateValue.startsWith("SG2")){ nextGateDue.setFormValue(sg2.getFormValue()) } if(nextGateValue.startsWith("SG3")){ nextGateDue.setFormValue(sg3.getFormValue()) } }

Hi Nandeesh

Have you looked at this documentation for ScriptRunner for JIRA?
https://scriptrunner.adaptavist.com/latest/jira/scripted-fields.html

In particular there are a set of examples that show you how to calculate values depending on other fields.

 

Phill 

Hi Phill, thanks for the link. But it doesn't help me to meet my requirement. I am not that good at scripting.if you can help me in scripting that would be very helpful for me. :) Many thanks, Nandeesh

Hi all,

Can any one help me in this please...

Thanks,

Nandeesh

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Sunday in Agility

You asked for it, so we delivered: images on issues have arrived

A picture tells a thousand words. And agility boards have just released their latest feature: cover images on issues – so now your board can tell a story at first glance. Upload attachmen...

775 views 3 11
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you