Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

JoeR
Contributor
February 7, 2013

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
Answer accepted
JoeR
Contributor
July 29, 2013

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.

0 votes
ShamhoonJ July 29, 2013

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

Thanks

Shamhoon.

0 votes
JoeR
Contributor
February 7, 2013

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

0 votes
JoeR
Contributor
February 7, 2013

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!

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2013

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.

0 votes
JoeR
Contributor
February 7, 2013

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.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2013

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.

0 votes
JamieA
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 7, 2013

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.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events