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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,460,023
Community Members
 
Community Events
176
Community Groups

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

fjodors Rising Star Mar 02, 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

0 votes
Answer accepted

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

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

fjodors Rising Star Sep 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

Hi Fyodor,

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

Regards,
Mart

fjodors Rising Star Oct 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();

Hi Fyodor,

Thanks, I'll test it now.

Regards,
Mart

Hi Fyodor,

It works! 
Thanks a lot!

Regards,
Mart

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)

 

/* 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]
}

 

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events