Forums

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

Insight Automation - Unable to resolve classes

Claire Berry
Contributor
May 2, 2023

Hi, 

I have created some Insight Automation which executes a Groovy script. The script works fine when used in scriptrunner script console. But when I add it to an Insight Automation rule, it does not work. 

I checked the server logs and found that the issue is it is unable to resolve some local and scriptrunner classes. 

Can anyone please tell me how I import these types of classes to work here?

Below is the errors:

Error when executing groovy script: /opt/atlassian/application-data/jira/shared/custom-jira-functions/insight-automation/ukicmdb/map-insight-user-to-jira-user.groovy

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

/shared/custom-jira-functions/insight-automation/ukicmdb/map-insight-user-to-jira-user.groovy: 9: unable to resolve class shared.User

 @ line 9, column 1.

   import shared.User

   ^

 

/shared/custom-jira-functions/insight-automation/ukicmdb/map-insight-user-to-jira-user.groovy: 8: unable to resolve class shared.Insight

 @ line 8, column 1.

   import shared.Insight

   ^

 

/shared/custom-jira-functions/insight-automation/ukicmdb/map-insight-user-to-jira-user.groovy: 10: unable to resolve class shared.Environment

 @ line 10, column 1.

   import shared.Environment

   ^

 

/shared/custom-jira-functions/insight-automation/ukicmdb/map-insight-user-to-jira-user.groovy: 7: unable to resolve class com.onresolve.scriptrunner.runner.customisers.WithPlugin

 @ line 7, column 1.

   import com.onresolve.scriptrunner.runner.customisers.WithPlugin

   ^

 

/shared/custom-jira-functions/insight-automation/ukicmdb/map-insight-user-to-jira-user.groovy: 6: unable to resolve class com.onresolve.scriptrunner.runner.customisers.PluginModule

 @ line 6, column 1.

   import com.onresolve.scriptrunner.runner.customisers.PluginModule

   ^

 

5 errors

3 answers

0 votes
Mark McCormack (Adaptavist)
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 Champions.
October 5, 2015

Here's an example we have used ourselves at Adaptavist:

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
// Get the Values of the Start date, End Date and Half Day fields and their values
def StartDate = getCustomFieldValue("Start date")
def EndDate = getCustomFieldValue("End date")
def halfday = getCustomFieldValue("Half Day")
 
//initialise some variables
float NumberOfDays = 0;
float TotalNumberOfDays = 0;
 
// Check if the user has requested a half day and if so set the time requested to half a day.
if (halfday != null) {
 TotalNumberOfDays = 0.5
 // If the user has not requested a half day calculate how many full days they have requested.
}else{
// Calculate the number of days that a user has requested
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(StartDate);
cal2.setTime(EndDate);
  
 while (cal1.before(cal2)) {
 // If the days include weekends skip those days and do not count them
 if ((Calendar.SATURDAY != cal1.get(Calendar.DAY_OF_WEEK))
 &&(Calendar.SUNDAY != cal1.get(Calendar.DAY_OF_WEEK))) {
 NumberOfDays++;
 cal1.add(Calendar.DATE,1);
 }else {
 cal1.add(Calendar.DATE,1);
 }
 }
 
 // Add on 1 day to include the start date which the calculation discards
 TotalNumberOfDays = NumberOfDays + 1
}
return TotalNumberOfDays.toString()
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 Champions.
September 9, 2015

+1 to what Steven said. If you looking at calculating a period between two days in working days, there are quite a few examples for that on stackoverflow.

0 votes
Steven F Behnke
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 Champions.
September 9, 2015

You've labeled this as Script Runner, but you used the verbage Calculated Field. Are you using fields of the 'Script Field' type (scriptrunner) or of the Calculated Date Field (misc calculated fields)? I cannot help you at all with Javascript in scriptrunner. Instead of this (the idea seems very convoluted and complicated) can you please describe what the value you're attempting to render in these fields, as a feature request or user story? I'm much better at that. :p

Suggest an answer

Log in or Sign up to answer