Hi Community!
Please help me with my behavior code:
def sourceReferral = getFieldByName("Off-site PM").getValue()?.toString() def sourceReferral2 = getFieldByName("PM / Off-site PM needed?") if(sourceReferral.getValue() == null ||sourceReferral.getValue().equals("")){ sourceReferral2.setFormValue(18422) }
Where sourceReferral = User Picker Field
sourceReferral2 = Single Select List
This code currently not working, maybe I did mistake somewhere?
Hi Sergey
So you have in the first line you get the string value
def sourceReferral = getFieldByName( "Off-site PM" ).getValue()?.toString() |
and in your if statement you are trying to get the value again.
And then I suppose the 18422 is the id of the option to set right ?
import com.atlassian.jira.component.ComponentAccessor def sourceReferral = getFieldByName("Multi User Picker").getValue() def sourceReferral2 = getFieldByName("Single Select") if (!sourceReferral) { // if is null or empty (which means no user selected) select list will have OptionA selected log.debug("Is empty I will set option") def cfConfig = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Single Select")?.getRelevantConfig(getIssueContext()) def optionToSet = ComponentAccessor.getOptionsManager().getOptions(cfConfig)?.find {it.value == "OptionA"}?.optionId sourceReferral2.setFormValue(optionToSet) } else { // else (if there is at least on user selected in the multi user group) single select list will have None as selected sourceReferral2.setFormValue(null) }
I bet this is more readable
regards
Thanos
Hi, Thanons!
You bet, I will!
So, this what we have after your expertise:
def sourceReferral = getFieldByName("User Multy Select").getValue()?.toString() def sourceReferral2 = getFieldByName("Single Select") def cfConfig = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Single Select")?.getRelevantConfig(getIssueContext()) def optionToSet = ComponentAccessor.getOptionsManager().getOptions(cfConfig)?.find {it.value == "OptionA"}?.optionId selectList.setFormValue(optionToSet) if(sourceReferral.getValue() == null ||sourceReferral.getValue().equals("")){ sourceReferral2.setFormValue(18422) }
Seems not excellent, can you review once again, please.
Many-many thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sergey I updated the original script above. In order to run the script every time the value of the multi user group changes, assign the above server side script in the
Field: Multi User Picker (or whatever you name it)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Thanos! It's worked!
Many-many thanks!
Kind Regards,
Sergey
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.