I am trying to figure out how to get the value of a project custom field that was created with ProFields. I have the below script that gets me the project from which I can see the values of standard fields. I am also able to identify the correct custom field. How do I get the value for this custom field for the given project?
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
def projectKey = "AIU20180523"
def projectManager = ComponentAccessor.projectManager
def projectService = ComponentAccessor.getComponent(ProjectService)
def existedProject = projectManager.getProjectObjByKey(projectKey)
if (existedProject) {
log.warn("The project with key ${projectKey} exists")
}
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey);
log.warn ("Project name: " + project.name)
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11000L);
log.warn ("Field name: " + customField)
As shown below the log is showing the correct results for everything scripted, I just need the actual value of the Adjusted Completion Date profiled custom field for the project key AIU20180523.
2019-04-16 15:27:06,603 WARN [runner.ScriptRunnerImpl]: The project with key AIU20180523 exists
2019-04-16 15:27:06,603 WARN [runner.ScriptRunnerImpl]: Project name: Avaya IC Upgrage-Exec
2019-04-16 15:27:06,603 WARN [runner.ScriptRunnerImpl]: Field name: Adjusted Completion Date
Hi Doug
I'm Carlos from DEISER development team.
Profields' fields are stored at project level. You must have a project field called *Adjusted Completion Date*
If you were mapped the Profields' field into a issue custom field and you are setting a script field of ScriptRunner you can get the value with:
issue.getCustomFieldValue(CustomField customField)
Your code will be:
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
def projectKey = "AIU20180523"
def projectManager = ComponentAccessor.projectManager
def projectService = ComponentAccessor.getComponent(ProjectService)
def existedProject = projectManager.getProjectObjByKey(projectKey)
if (existedProject) {
log.warn("The project with key ${projectKey} exists")
}
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey);
log.warn ("Project name: " + project.name)
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObject(11000L);
log.warn ("Field name: " + customField)
def value = issue.getCustomFieldValue(customField)
you can also get the value directly from the Profields' field, if you have problems with previous code don't hesitate to ask me.
Regards.
Carlos
Hi Carlos,
Thank you for the reply. I am new to all of this, so I am not quite following along. I am using this Profields field at the project level, so I do not actually have an issue to look up. As a result, when adding "def value" as indicated, I receive the following:
You mention that I can get the value directly from the Profields field. What would the code be for doing this for the specific project for which I have established context based on the given projectKey?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have figured out what I need to do. In case anyone else comes across this post, here is the code that allowed me to get the value:
import com.atlassian.jira.bc.project.ProjectService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.deiser.jira.profields.api.field.FieldService
import com.deiser.jira.profields.api.value.ValueService
import com.deiser.jira.profields.api.field.date.DateField
@WithPlugin("com.deiser.jira.profields")
def projectKey = "AIU20180523"
def valueService = ComponentAccessor.getOSGiComponentInstanceOfType(ValueService.class)
def fieldService = ComponentAccessor.getOSGiComponentInstanceOfType(FieldService.class)
def projectManager = ComponentAccessor.projectManager
def projectService = ComponentAccessor.getComponent(ProjectService)
def existedProject = projectManager.getProjectObjByKey(projectKey)
if (existedProject) {
log.warn("The project with key ${projectKey} exists")
}
def project = ComponentAccessor.getProjectManager().getProjectByCurrentKey(projectKey);
log.warn ("Project name: " + project.name)
def dField = fieldService.get(27) // 27 is the Profields ID for the Adjusted Completion Date
log.warn ("Field name: " + dField)
def dAdjustedCompletionDate = valueService.getValue(project,(DateField) dField)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Doug.
Sorry I didn't see those replies. I think you were in a issue script field context and it seems that you were in a console script or similar and because of that you didn't have the issue object.
I'm really glad that you made it work.
Regards, Carlos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Doug Snyder ,
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.
In the line
//def appManagerValue = valueService.getValue(project, appManager).toString();
I am not sure you are making the call correctly. From your code snippet I cannot tell the type of your CustomerFieldID, but that needs to be included in the call to the getValue method. However, note that in the call I make in my code, I have identified that the Profields field is a DateField in the call:
def dAdjustedCompletionDate = valueService.getValue(project,(DateField) dField)
and I have included an import for Profield date fields:
import com.deiser.jira.profields.api.field.date.DateField
You may want to review the API documentation to see the proper way to make the call to getValue based on your data type.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Doug Snyder ,
Thank you for the suggestions.
It worked. I changed the line to:
def appManagerValue = valueService.getValue(project, (TextField) appManager).toString()
and added:
import com.deiser.jira.profields.api.field.text.TextField
Best Regards
Swapnil Srivastav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.