Script runner - access fields from Profields plugin

fjodors
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.
February 27, 2018

Hello

Is it possible to accessProfields plugin's values through ScriptRunner?

For.e.g. I'd like to get profields values from custom REST endpoint.

When I am importing profields classes, it shows me an error

"Unable to resolve class com.deiser.jira........" (see attached screenshot)

 

script runner and profields.png

Thank you in advance!

Fyodor

2 answers

1 accepted

0 votes
Answer accepted
Adrián Plaza [DEISER]
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.
February 27, 2018

Hi Fyodor,

It's a pleasure to hear from you again :)

You can find the solution in this post: https://scriptrunner.adaptavist.com/latest/jira/scripting-other-plugins.html

In this case, the code gets the value of the status field in a project:

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.status.StatusField
import com.atlassian.jira.issue.Issue

@WithPlugin("com.deiser.jira.profields")

Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("SCRUM-7")

def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)

def statusField = fieldService.get(9) //ID of field Status

return valueService.getValue(issue.projectObject,(StatusField) statusField)

 

You can find all the API info of versión 5.5.4: http://profields.javadoc.deiser.com/5.5.4/

Regards,

Adrián.

fjodors
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.
February 27, 2018

Hello Adrian

Thank you for advice.

 

Fyodor

Kiranped April 17, 2018

Hi Adrian,

I am using prifields api in one of my custom JIRA plugin.

I have implemented in a similar fashion as per your post bet getting below Error.

valueService.getValue(issue.projectObject,(StatusField) statusField)

 Error Log :

java.lang.ClassNotFoundException:com.deiser.jira.profields.api.field.status.StatusField

not found by com.org.jira.plugin.synch-onejira-plugin [276]

at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1532)

at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:75)

at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1955)

at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

at com.org.jira.plugin.ojira.wf.postfunction.SetChannelFieldPostfunction.calculateChannelFieldValue(SetChannelFieldPostfunction.java:138)

Adrián Plaza [DEISER]
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.
April 17, 2018

Hi @Kiranped,

 

What version of Profields plugin do you have installed?

 

Cheers,

Adrián.

Kiranped April 17, 2018

Profields 5.3.0 and jira 7.6.0

Adrián Plaza [DEISER]
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.
April 18, 2018

Hi @Kiranped,

 

Can you update Profields plugin to the last version and do the same test?

 

Cheers,

Adrián.

Kiranped June 5, 2018

@Adrián Plaza [DEISER],

 

I have tried with 5.6.3 version and JIRA 7.6 version. I am facing the same problem.

Profield Type: Select List (single choice)

I am using ListField

 

private Field getPartnerVisibleProField(){

List<Field> fields = fieldService.get();

for (Field field : fields){

if ("Field_Name".equals(field.getName())){

return field;

}

return null;

}

valueService.getValue(issue.projectObject,(ListField) getPartnerVisibleProField()) // 

java.lang.NullPointerException

 

*********************************StatusField case******************************

if I typecast to (StatusField)getPartnerVisibleProField(), getting null object but I have a value updated

albertogb July 27, 2018

Muy buenas Adrian,

Estoy evaluando el plugin y necesito saber si puedo cambiar un campo de tipo status en una postfuntion de script runner.

Por ejemplo:

Al ejecutar un bloqueo de una tarea que el campo status del proyecto cambie a bloqueado. ¿tienes un ejemplo para orientarme?

 

Un saludo.

I am evaluating the plugin and I need to know if I can change a field of type status in a postfuntion of script runner. For example: When executing a block of a task, the status field of the project changes to blocked. Do you have an example to guide me? A greeting.

0 votes
Monika Agarwal December 1, 2019

@fjodors - Is this issue resolved. I am also facing the same issue.

fjodors
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.
December 1, 2019

Hi

Yes, you need to add @WithPlugin("com.deiser.jira.profields") command, then you can use profields methods and classes.

See related issues

Monika Agarwal December 1, 2019

Hey, I have done this through REST End Point and it is working. But while I am executing same script via custom script applied on post function of the jira workflow. It shows the error.

Suggest an answer

Log in or Sign up to answer