Forums

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

Script runner - Access to Component of third part plugins (like Profields plugin, or any other)

Vincent Thoulé _Alkaes_ April 5, 2018

Hello

I have, 2 months ago, implemented a Script Post-Function with Scriptrunner where I was accessing Profield plugin from Deiser.
It looks like as follow ...

import com.deiser.jira.profields.api.project.SearchService
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.Field

import com.deiser.jira.profields.api.field.item.list.ListItem
import com.deiser.jira.profields.api.field.item.list.ListItemService
import com.deiser.jira.profields.api.field.textmultiple.TextMultipleField
import com.deiser.jira.profields.api.field.list.multiple.ListMultipleField
...
class MyClass {
@PluginModule
static FieldService fieldService
@PluginModule
static ValueService valueService
@PluginModule
static SearchService searchService
@PluginModule
static ListItemService listItemService

ListMultipleField projectModelField

def String getProjectModel (Project _project) {
String projectModel = null;
def List<ListItem> projectModelFieldItems = valueService.getValue(_project, projectModelField)
if (projectModelFieldItems.size() > 0) {
projectModel = projectModelFieldItems.iterator().next().value
}
return projectModel
}
...
}

This morning, since I had to build new process with a similar implementation, I have accessed the active workflows in order to extract the Post-Function Script as model.
And strange, the script was marked in error as described in https://community.atlassian.com/t5/Jira-questions/Script-runner-access-fields-from-Profields-plugin/qaq-p/738235

The feature was always operational, and no error was reported by our users.
I have then edited the Workflow in order to understand the root cause of errors.

Without explanation, I tried to reproduce the error in a Dev. envinronment. It was the same.
Then, since I did not have used the @WithPlugin annotation, I decided to implement it.
I begin to write the correct syntaxe it on Scriptrunnner Console.
After having elaborate the correct script, I swicth to the Scriptrunner Post-Function, and surprise, there was no more error.

I have no idea about what could be the root cause of this behaviour. It is as if a 1st usage of @WithPlugin("com.deiser.jira.profields") caused a an availability of the component in any Scriptrunner scritps, in a cache. Since the previous restart of JIRA, the component was no more avaialble until a new usage of @WithPlugin("com.deiser.jira.profields").

In doubt, I have added the @WithPlugin("com.deiser.jira.profields") ... and I will se after next JIRA restart.

Any idea ?

Thanks by advance
Vincent

1 answer

0 votes
david
Atlassian Partner
April 5, 2018

Hello @Vincent Thoulé _Alkaes_, it seems that you haven't used the function @WithPlugin("com.deiser.jira.profields") in the original script. This is mandatory to access add-on functions in Script Runner. 

After you added it, does it work?

Vincent Thoulé _Alkaes_ April 5, 2018

Hi David,

It is exact ... I did not have used the @WithPlugin annotation in this script, but in others (RestPoint), but it worked.

The error was displayed only when accessing the source code since a long time (after different restart).

I have added the annotation just today and will see how it will evolve.

It works for the moment.

My focus is also to understand why it worked without the annotation !

V.

david
Atlassian Partner
April 5, 2018

I see your point @Vincent Thoulé _Alkaes_, I guess is something that our friends from Adaptavist can answer much better than us.

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events