Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set an Tempo Account field when creating an issue using the Java API

Jens Kisters //SeibertSolutions
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2019

Hello,

i am having trouble setting a Tempo Account field like this:

 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService.CreateValidationResult
import com.atlassian.jira.util.ErrorCollection
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.user.ApplicationUser

IssueService issueService = ComponentAccessor.getIssueService()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
UserManager userManager = ComponentAccessor.getUserManager()
IssueManager issueManager = ComponentAccessor.getIssueManager()
ApplicationUser user = userManager.getUserByKey("aptisAdmin")


IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();

issueInputParameters.setProjectId(10400L)
issueInputParameters.setDescription("description");
issueInputParameters.setSummary("summary")
issueInputParameters.setIssueTypeId("10001")
issueInputParameters.setReporterId("aptisAdmin")
String tempoValue = "ACCOUNTNAME"
//tempoValue = "3" // accountID did not work either
CustomField tempoAccountField = customFieldManager.getCustomFieldObjectByName("Account")
issueInputParameters.addCustomFieldValue(tempoAccountField.getId(), tempoValue)

CreateValidationResult createValidationResult = issueService.validateCreate(user, issueInputParameters);

if (createValidationResult.isValid())
{
//do stuff here
} else {
log.error 'Create Result not valid'
ErrorCollection errors = createValidationResult.getErrorCollection()
for (String error : errors ) {
log.error error
}
}

addCustomFieldValue expects a String, but i cant find any documentation on how to properly format the string so that the field will be set to a value.

In the system the account field is obligatory, using both the accountId and the account Key i get an invalid CreateValidationResult with the Error:

Error Messages: [Account: Account ist erforderlich.] 

(in english Account is required)

 

thanks in advance

Jens

2 answers

0 votes
Jens Kisters //SeibertSolutions
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 21, 2019

@Greg Fischer : I worked around the probem by setting a default account on the projects in question.

0 votes
Jens Kisters //SeibertSolutions
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 16, 2019

Supplying a json in the format that a set Account field has in the Jira Rest API doesnt work either

Greg Fischer
Contributor
July 19, 2019

Hi Jens,

 

Did you ever get this to work?  I need to do the exact same thing (create an issue where the Tempo Account field is a required field at create time), but from a workflow post-transition Groovy script.  I have tried getting all the valid Account objects using Loic's solution here: https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Tempo-Java-API-documentation/qaq-p/886471

but I keep getting a  java.lang.NoClassDefFoundError: com/tempoplugin/accounts/account/api/AccountService when it runs.  The ScriptRunner Groovy editor gives me a green light so it doesn't find anything wrong.

 

Thanks,

-Greg

Greg Fischer
Contributor
July 19, 2019

Never mind.  I did get this to work by using the Account ID, so

CustomField account = customFieldManager.getCustomFieldObjectByName("Account")

IssueInputParameters reqIssueInputParameters = issueService.newIssueInputParameters();
reqIssueInputParameters.addCustomFieldValue(account.getIdAsLong(), accountID)

 

where the accountID variable is a String.

Suggest an answer

Log in or Sign up to answer