Example Set one field based on another field with information provided by the server

Attempting to use an example in the following link called "Set one field based on another field with information provided by the server", that is I'm trying to update a value based on the value of a select list. I'm new to Jira, I don't know groovy, etc. I'll try to get a log in the meantime, don't have access to the server.

https://jamieechlin.atlassian.net/wiki/display/JBHV/JIRA+Behaviours+Plugin#JIRABehavioursPlugin-Setonefieldbasedonanotherfieldwithinformationprovidedbytheserver

It appears others have had the same issue (see following link), don't see a resolution, I'm on Plug-in v0.5.3, Jira 5.1.4. If that is the issue, please let me know! Otherwise read on. here's an issue with the example. I added the first line of my code based on this issue, still doesn't function.

I'm not sure why the "String componentLead" line of code was included. Is it needed or is some code missing?

https://answers.atlassian.com/questions/55298/how-to-get-component-lead-according-to-chosen-component-when-using-jira-behaviours-plugin

import com.atlassian.jira.bc.project.component.ProjectComponent
FormField formComponent = getFieldById(fieldChanged)
FormField formAssigneeOtherField = getFieldByName("Assignee Other")
String componentLead
List<ProjectComponent> components = formComponent.getValue() as List
// List components = formComponent.getValue() as List
// if any components have been set, set the user field to the component lead of the first component
// otherwise unset it
if (components) {
    formAssigneeOtherField.setFormValue(components.first().lead)
}
else {
    formAssigneeOtherField.setFormValue("")
}

Questions:

1) do I need to reindex?

2) do I always need to clear serverside cache?

3) is there another way to set a field value based on another field value?

Thanks.

8 answers

1 accepted

0 votes
Accepted answer

Our company decided to not use the Behaviours plug-in due to this issue and several others Recently I've been using the Script Runner plug-in with "Has Custom Field value equal to". I put the logic on the Create Issue Workflow transition. This is ok for the creation of an issue but the validation only fires on the create. If someone opens the issue in Edit, the validation doesn't fire. Javascript is another option, but I haven't found good examples that work consistantly. I think some of the plug-ins work well for simple validation, but when the validation is complex the plug-ins don't always work or it's difficult to code. In some cases, we have just created another issue type to eliminate doing validation of select lists.

That's just an example that sets a field to the component lead. What is it that you're trying to do? This code will only work if you have a field called "Assignee Other", and your components have a lead defined.

-> String componentLead

It's not needed in the code above.

The purpose of doing this with the behaviours plugin is it sets the value in the form as the user make changes. If you want the user can then change the "assignee other". If you just want to set the value of a field it's easier to do this in a post-function or a listener.

Thanks for the quick response.

I may be confused about the use of the term "lead". I'm looking at the field called Component/s, there are four possible values: Email, Fax, Letter, Phone.
I thought whatever value I selected of the four values was the "lead"...is this incorrect? Likely.

I'd like to either pass the value I selected to field Assignee Other or take the value and do some logic on it. Such as, If "Email", set field Assignee Other to USPS or If "Fax", set Assignee Other to Sprint, etc. I can't seem to get Assignee Other to populate with anything.

Thx. I can send a screenshot.

Lead is the component lead. Make sure your behaviour is actually mapped to a project, and that the script is attached to the components field. But you will need to look at more examples to do what you want.

Jamie, thanks for your replies. I've made progress, I can get the value that I select in a Component to display in another field. But if I remove everything from a component, the related field does not get refreshed properly. Since I don't have access to the log files yet I'm displaying the contents of the component to another field and it shows there is data in that component even though the component field displays on the screen as empty and the red * redisplays. See attached pdf, thanks!

I'm using a server-side script.

import com.atlassian.jira.bc.project.component.ProjectComponent
FormField formComponent = getFieldById(fieldChanged)
FormField formAssigneeOtherField = getFieldByName("Assignee Other")
FormField formDateOnLetterField = getFieldByName("Date on Letter")

List<ProjectComponent> components = formComponent.getValue() as List

//I added this setFormValue to display the contents of the component to the Date on Letter field

formDateOnLetterField.setFormValue(formComponent.getValue())

if (components) {
formAssigneeOtherField.setFormValue(components.first().name)
}
else {
formAssigneeOtherField.setFormValue("")
}

Hi Rohan , Did you solve this issue? I am having the same problem.

Thanks

Shamhoon.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,408 views 0 8
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