Fill customfield with reporter name using Script Runner

Leos Junek
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.
June 11, 2014

Hello to all,

I am using JIRA 6.2.3 and accidentaly upgraded Behaviours Plugin, that is no longer supported in JIRA 6.2.x. It was merged into Script Runner plugin. Now I have to restore some functionality with Script Runner, but code from Behaviours field definition

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser

FormField formTester = getFieldByName("Tester2");
ApplicationUser appUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
User user = appUser.getDirectoryUser();
String currUserFullName = user.getDisplayName();
String currUserName = user.getName();
log.error (currUserFullName);
log.error (currUserName);
if(!formTester.getFormValue()){
  formTester.setFormValue(currUserName);
}

returns (when clicking at Go)
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script13.groovy: 5: unable to resolve class FormField 
 @ line 5, column 11.
   FormField formTester = getFieldByName("Tester2");
             ^

1 error

A stacktrace has been logged.

My task is to populate custom field Tester2 (customFieldId=11030) with username of reporter at the time of issue creation. User Picker is the template I have selected at script definition.

What should I import to be able to use class FormField, or is there any alternative to that class?

I would be grateful for any hint.

Leos

2 answers

1 accepted

1 vote
Answer accepted
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.
June 11, 2014

I recommend that you install Script Runner 3.0-beta, which you seem to already have, and uninstall the behaviours plugin. Obviously on a test instance first, hopefully it is not too late for that advice.

You cannot mix and match behaviours scripts with script runner scripts. Well, they are both groovy, except behaviours has specific methods available like getFieldByName, that are only available in the context where it makes sense.

Can you post a screenshot of where this is configured? That might help.

But your code, if it's a behaviours script, looks correct at first glance.

Leos Junek
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.
June 11, 2014

My response is below, as an answer, because "Sorry, our spambot thinks your comment is spam. Please post an answer instead."

Leos Junek
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.
June 12, 2014

I have uploaded 3.0-beta-10 version of plugin via UPM and it works as before. Behaviours appeared again and they're working. Thanks :-)

0 votes
Leos Junek
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.
June 11, 2014

Hello Jamie,

nice to hear from you. I cannot upgrade to 3-0beta. My version was the latest Script Runner available in Atlassian Marketplace (2.1.17) at the time of posting my question. According to page Installation of versions from 2.0.0 upwards I stopped JIRA, deleted old groovy-runner-all-*.jar files, download groovyrunner-3.0-beta-10.jar and moved it to ${CATALINA_HOME}/work/Catalina/localhost/_/WEB-INF/lib folder (JIRA was installed from WAR at Linux, it is run with root context) and started JIRA. But no plugin was installed or available in Find new addons menu, only Script Runner 2.1.17 is available for me. Have you publish step-by-step an upgrading guide when installing 3.0beta? Can you tell me what to do to perform upgrade?

Here is original version of behaviour code

<config use-validator-plugin="false" validate-jira-requiredness="false" name="PoleTester" description="Pole Tester se automaticky vyplnuje  zadavatelem" guideWorkflow="null">
  <field id="customfield_10013" required="null" readonly="null" hidden="null" validator="server" validator-class="" validator-script="import com.atlassian.crowd.embedded.api.User;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.user.ApplicationUser;
 
 
FormField formTester = getFieldByName("Tester");
ApplicationUser appUser = ComponentAccessor.getJiraAuthenticationContext().getUser();
User user = appUser.getDirectoryUser();
String currUserFullName = user.getDisplayName();
String currUserName = user.getName();       
          
log.error (currUserFullName);
log.error (currUserName);
          
if(formTester.getFormValue() == ""){

if(formTester.getFormValue() == ""){
  formTester.setFormValue(currUserName);
  }
}" validator-method=""/>
</config>

I tried to separate groovy script, omitting JavaScript tags. But as you can see, I was not successful.

Regards

Leos

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.
June 11, 2014

It's a plugins2 plugin so you need to upload through the UPM.

Suggest an answer

Log in or Sign up to answer