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

This widget could not be displayed.

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()) } }

This widget could not be displayed.

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

This widget could not be displayed.

Hi all,

Can any one help me in this please...

Thanks,

Nandeesh

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

154 views 1 3
Join discussion

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