Fill customfield with reporter name using Script Runner

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

This widget could not be displayed.

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.

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

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 :-)

This widget could not be displayed.

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

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted 6 hours ago in Jira

Atlassian Research Workshop opportunity on Sep. 28th in Austin, TX

We're looking for participants for a workshop at Atlassian! We need Jira admins who have interesting custom workflows, issue views, or boards. Think you have a story to sha...

23 views 1 2
Join discussion

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