When the user selects "Yes" on a field I want the next fields to be populated/copied from existing fields on the issue.
I have tried this but i know its not correct...
def selectListPreferred = getFieldById(getFieldChanged())
String selectListPreferredValue = selectListPreferred.getValue()
selectListPreferred.clearError()
def cfApart = getFieldByName("Confirmed Apartment Name/Number")
def cfProApart = getFieldByName("Proposed Apartment Name/Number")
def cfProApartValue = cfProApart.getValue()
if (selectListPreferredValue == "Yes" )
{
cfApart.setFormValue(cfProApartValue)
}
else if (selectListPreferredValue == "No" )
{
cfApart.setFormValue(null)
}
import com.atlassian.jira.component.ComponentAccessor;
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
def selectListPreferred = getFieldById(getFieldChanged())
String selectListPreferredValue = selectListPreferred.getValue()
selectListPreferred.clearError()
def cfApart = getFieldByName("Confirmed Apartment Name/Number")
def cfUprnreas = getFieldByName("Confirmed UPRN Reason Code")
def cfApartPro = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Proposed Apartment Name/Number")
def cfUprnreasPro = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Proposed UPRN Reason Code")
def check4 = underlyingIssue.getCustomFieldValue(cfApartPro).toString()
def check13 = underlyingIssue.getCustomFieldValue(cfUprnreasPro).toString()
if (selectListPreferredValue == "Yes" )
{
cfApart.setFormValue(check4)
cfUprnreas.setFormValue(check13)
}
else if (selectListPreferredValue == "No" )
{
cfApart.setFormValue(null)
}
Your code mostly seems correct.
I assume you have created a Server-Side Behaviour for the Select List Preferred field. Please confirm this. Kindly share a screenshot of your Behaviour configuration.
For your code, I suggest modifying the code slightly to:-
def selectListPreferred = getFieldById(fieldChanged)
def selectListPreferredValue = selectListPreferred.value.toString()
def cfApart = getFieldByName('Confirmed Apartment Name/Number')
def cfProApart = getFieldByName('Proposed Apartment Name/Number')
def cfProApartValue = cfProApart.value
cfApart.setFormValue(null)
if (selectListPreferredValue == 'Yes' ) {
cfApart.setFormValue(cfProApartValue)
}
If your behaviour configuration is correct, the code above will work as expected. But to double confirm, sharing a screenshot of the Behaviour config would be best.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram,
Thanks for the help. Ive got it to work for text fields, but it doesnt want to work for select lists.
Thanks
Rob
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your last comment, you mentioned:-
Ive got it to work for text fields, but it doesnt want to work for select lists.
Could you please share the Behaviour code you are using for the Select Lists?
Also, it would be very helpful if you could also include a screenshot of the Server-Side Behaviour configuration for the Select List.
I am looking forward to your feedback.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ram,
Not too sure what you mean by Server-Side behaviour config, but here is my code
import com.atlassian.jira.component.ComponentAccessor;
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
def selectListPreferred = getFieldById(getFieldChanged())
String selectListPreferredValue = selectListPreferred.getValue()
selectListPreferred.clearError()
def cfApart = getFieldByName("Confirmed Apartment Name/Number")
def cfUprnreas = getFieldByName("Confirmed UPRN Reason Code")
def cfApartPro = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Proposed Apartment Name/Number")
def cfUprnreasPro = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Proposed UPRN Reason Code")
def check4 = underlyingIssue.getCustomFieldValue(cfApartPro).toString()
def check13 = underlyingIssue.getCustomFieldValue(cfUprnreasPro).toString()
if (selectListPreferredValue == "Yes" )
{
cfApart.setFormValue(check4)
cfUprnreas.setFormValue(check13)
}
else if (selectListPreferredValue == "No" )
{
cfApart.setFormValue(null)
}
"Confirmed UPRN Reason Code" is the select list
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your last comment, you mentioned:-
Not too sure what you mean by Server-Side behaviour config, but here is my code
What I am referring to is a screenshot like the one below:-
I need to view this to confirm if your Behaviour is configured correctly according to the field that is declared to ensure that the code will work correctly.
In the latest code you have provided, you have declared your list as:-
def selectListPreferred = getFieldById(getFieldChanged())
String selectListPreferredValue = selectListPreferred.getValue()
Can you please change it to the structure that I have given in my previous comment, i.e.:-
def selectListPreferred = getFieldById(fieldChanged)
def selectListPreferredValue = selectListPreferred.value.toString()
Also, why have you declared the fields as:-
def cfApartPro = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Proposed Apartment Name/Number")
def cfUprnreasPro = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects().findByName("Proposed UPRN Reason Code")
There is no point in invoking the fields as such.
In addition to that, why have you initialised the field using the underlyingIsuse as shown below:-
def check4 = underlyingIssue.getCustomFieldValue(cfApartPro).toString()
def check13 = underlyingIssue.getCustomFieldValue(cfUprnreasPro).toString()
I suggest correcting your code to:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def selectListPreferred = getFieldById(fieldChanged)
def selectListPreferredValue = selectListPreferred.value.toString()
selectListPreferred.clearError()
def cfApart = getFieldByName('Confirmed Apartment Name/Number')
def cfUprnreas = getFieldByName('Confirmed UPRN Reason Code')
def cfApartPro = getFieldByName('Proposed Apartment Name/Number')
def check4 = cfApartPro.value.toString()
def cfUprnreasPro = getFieldByName('Proposed UPRN Reason Code')
def check13 = cfUprnreasPro.value.toString()
cfApart.setFormValue(null)
if (selectListPreferredValue == "Yes" ) {
cfApart.setFormValue(check4)
cfUprnreas.setFormValue(check13)
}
I am looking forward to your feedback and clarification.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"Confirmed Apartment Name/Number" is not being populated with "null" and the select list "Confirmed UPRN Reason Code" is not being populated as it wasnt in my code. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
From the screenshot you provided, it appears you are using a pretty old version of ScriptRunner. Could you please clarify what version you are currently using?
Also, if you are using Jira version 8.16 and above, I suggest that you upgrade your ScriptRunner plugin to the latest release, i.e. 8.7.1 as there are many fixes since the current release you are using.
In addition to that, have you created a Transition screen for this Behaviour? I am asking this because, from the condition that you have added, it appears that the Behaviour is expected to trigger on the Wholesaler Case Complete transition.
Looking forward to your feedback and clarification.
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We are on Jira 7.13.1 . We cant upgrade at this time.
I have a screen for the transitions (below) which allows me to select "Yes". My original code works fine, just not on select list. In the screenshot you will see many more fields, but i took them out the code i sent as it was too big to send. Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Jira and ScriptRunner versions you are currently using are pretty old.
Regarding the problem you are encountering, it looks like a Behaviour bug which was fixed a long time ago.
The only way I would recommend to proceed is first to upgrade both your Jira Server / DC and ScriptRunner.
Thank you and Kind regards,
Ram
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.