Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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
Community showcase

All you wanted to know about customer support KPIs

When working in customer support, it’s crucial to calculate, analyze and monitor specific numbers, called KPIs (Key Performance Indicators). They go hand-in-hand with customer satisfaction, problem d...

107 views 1 5
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you