my jira version is jira 4.4.1,Behaviours Plugin version:0.5.0
there are two fields:User and Component
what i want to implement is :
when select a component ,the field "User" will be set to the component lead's user name.
If you unselect the component or select Unknown it should be cleared.
i refer to the Behaviours Plugin document(https://studio.plugins.atlassian.com/wiki/display/JBHV/JIRA+Behaviours+Plugin#JIRABehavioursPlugin-Installation),and find the script follows,
FormField formComponent=getFieldById("components") FormField formUserField=getFieldByName("customfield_11000") List<ProjectComponent> components=formComponent.getValue() as List if(components){ formUserField.setFormValue(components.first().lead) }else{ formUserField.setFormValue("") }
there are some compilation errors,
Compilation failure: startup failed: Script1.groovy: 6: unable to resolve class ProjectComponent @ line 6, column 6. List<ProjectComponent> components=formComponent.getValue() as List ^ 1 error
You can either add the import statement for ProjectComponent, or easier, just remove the generic, ie remove <ProjectComponent>.
i add the import statement,now it compile succeed ,but the field "User" is not changed yet(it is always "blank") ,no matter which component i choose .
the script is
import com.atlassian.jira.bc.project.component.ProjectComponent FormField formComponent=getFieldById("components") FormField formUserField=getFieldByName("customfield_11000") List<ProjectComponent> components=formComponent.getValue() as List if(components){ formUserField.setFormValue(components.first().lead) }else{ formUserField.setFormValue("") }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This line:
FormField formUserField=getFieldByName(
"customfield_11000"
)
should be:
FormField formUserField=getFieldById(
"customfield_11000"
)
by name means give the name, eg "Name of custom field".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
yes ,FormField formUserField=getFieldById(
"customfield_11000"
) is effective.
and FormField formUserField=getFieldByName("User") will get the same result.
but ,there is still one problem,when i have selected one component ,for example "component1" whose associated component leader is "Jim",and the field "User" will display as "Jim"
then i select Unknown,the "User" is not cleared,it still display as "Jim"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What's "Unknown"? That does not display in the components field, is it the name of a component you created?
I presume you've put this script on the components field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"Unknown" is one of Component's option value
<select class="select " id="components" multiple="multiple" name="components" size="3" data-remove-null-options="true"> <option value="-1"> Unknown </option> <option selected="selected" title="A " value="10101"> A </option> <option title="B" value="10100"> B </option> </select>
when i select option A ,and view source code of the jira web page.and find that,
<option selected="selected" title="A" value="10101">
the attribute selected="selected" is added to option A.
then i select the option "Unknown" ,option A still has the attribute selected="selected" ,while option "Unknown" doesn't have the attribute
so ,i think this can explain why the field "User" still display as previous selected "A"'s value,although i have changed Component's value to "Unknow"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
now,i have understand most of this example's code
1, List<ProjectComponent> components=formComponent.getValue() as List
"formComponent.getValue()" returns Component objects,and "as List" means convert type to List("as" is groovy syntax)
2, formUserField.setFormValue(components.first().lead)
"components.first() " return the first item in the list form groovy syntax
"lead" returns the name of the lead for this project component,i searched the method without result,but
found getLead() method from JIRA API. i replace "lead" with "getLead()" ,and get the same result
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
with this line *formUserField.setFormValue(components.first().lead)* I got the userID, how can I get the Lead Name?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
depends on your jira version, getComponentLead should give you an ApplicationUser in recent versions.
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.