Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Profields API 4.10 - get value of specific Profields List Field in specific project

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.
March 2, 2018

Hello


I am trying to get value of specific Profields List Field in specific project.

My code is:

def ProfieldsValueService = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectValueService.class);
def ProfieldsFieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class);

//field ID in profield scheme
def ClientFieldID=1;
ProfieldsField ClientFieldObj = ProfieldsFieldService.get(ClientFieldID);

try{
    Object ClientFieldValueObj=ClientFieldObj.getValueInProject(projObj);
    ClientFieldValueStr=ClientFieldValueObj.toString();

}
catch(def exception){
    ClientFieldValueStr='***unable to get Customer for issue '+iss.key;
}


Variable ClientFieldValueStr returns me "[com.deiser.jira.profields.projectvalue.SourceValueImpl@23f7df76]" instead of field value.
From API documentation (http://profields.javadoc.deiser.com/4.10.1/) it seems I should use SourceValue/SourceService interfaces, but I don't understand how....

Could you help me?


Thank you!

Fyodor

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
carlos.fernandez
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.
September 20, 2018

Hi Fyodor

Because the field is a ListField, the method you are using is like:

List<SourceValue> getValueInProject(Project project)

It returns a list of values (SourceValue) that has three properties: key, parentKey and value.

Then, you need to iterate over the list and get the value of each item. If your field is a simple list, you only need to get the first element and then its value.

This is your code modified:

import com.atlassian.jira.component.ComponentAccessor
import com.deiser.jira.profields.api.projectvalue.ProjectValueService
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.ProfieldsField

def profieldsValueService = ComponentAccessor.getOSGiComponentInstanceOfType(ProjectValueService.class);
def profieldsFieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class);

// Project Key
def projectKey="ONE"
// Field Id
def fieldId=1

def value=null
try{
def listField = profieldsFieldService.get(fieldId)
def project = ComponentAccessor.projectManager.getProjectObjByKey(projectKey)
def clientValue = listField.getValueInProject(project)
value = clientValue[0].value
}
catch(def exception){
value = '***unable to get Customer for issue '+iss.key;
}

return value


Hope it helps.

Carlos

carlos.fernandez
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.
September 20, 2018

And sorry for the delay in answer, I didn't see that the question was wrote in March

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.
September 20, 2018

Hello Carlos

We already updated our profield module till 5 version, this new version has more usable API and I was able to get all values.

Anyway, thank you for reply, it will be helpful for older jira/profield instances.

Regards,
Fyodor

Mart Wilson Lim October 10, 2018

Hi Fyodor,

May see the sample script you sued to get the field values?

Regards,
Mart

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.
October 10, 2018

Try this

import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.Field
import com.deiser.jira.profields.api.field.list.ListField
import com.deiser.jira.profields.api.value.ValueService

@WithPlugin("com.deiser.jira.profields")
...
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
...
def CustomerFieldID = 11;
Field myListField = fieldService.get(CustomerFieldID);
def ClientFieldValueStr = valueService.getValue(projObj,(ListField) myListField).toString();
Mart Wilson Lim October 10, 2018

Hi Fyodor,

Thanks, I'll test it now.

Regards,
Mart

Mart Wilson Lim October 11, 2018

Hi Fyodor,

It works! 
Thanks a lot!

Regards,
Mart

SWAPNIL SRIVASTAV
Contributor
May 27, 2020

Hello @fjodors  and @carlos_fernandez ,

I am trying to get the value of a text type Project field/ Profield in Escalation Services of Script Runner. I have tried this script but it gives a Static type check error at the last line "Cannot find matching method". Neither the last line works not the second last (the one which is commented). Kindly help

import com.atlassian.jira.component.ComponentAccessor
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.Field
import com.deiser.jira.profields.api.value.ValueService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

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

def projectKey = "XXXX"

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


def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey);
log.error "Project name: " + project.name

def CustomerFieldID = 1;
Field appManager = fieldService.get(CustomerFieldID);
//def appManagerValue = valueService.getValue(project, appManager).toString();
def appManagerValue = appManager.getValueInProject(project)

0 votes
Chand Chandrasegaram
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 8, 2020

 

/* Tested on Profields 7.5.0 and Jira Server 8.5.3 */
import com.atlassian.jira.component.ComponentAccessor
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.field.Field
import com.deiser.jira.profields.api.value.ValueService


def profieldsValueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class);
def profieldsFieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class);

def pkey = "JT"
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKeyIgnoreCase(pkey)
def fieldId = 1 //Profield ID
def fieldValue = null

Field listField = profieldsFieldService.get(fieldId)
if (listField) {
fieldValue = profieldsValueService.getValue(project, listField)
log.warn "Field_Value: " + fieldValue
log.warn "Single_select_Profield_value: " + fieldValue[0]
}

 

TAGS
AUG Leaders

Atlassian Community Events