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

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
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

78 views 1 6
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