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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Fyodor,
May see the sample script you sued to get the field values?
Regards,
Mart
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
/* 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]
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.