Skip to main content
Skip table of contents

Java API - Use Elements Connect API in Jira actions processing v6.0



Use case

Sometimes, you want to populate Elements Connect custom field during Jira actions processing. Jira has its own business model objects (like IssueInputParameters or CustomFieldParams) wich are forwarded throught actions chain. This is how you can use Elements Connect API to make it work.

Using the API

The following example shows how to set a value of a Standard Elements Connect field:



Java example

GROOVY
	import com.atlassian.jira.issue.Issue;
	import com.atlassian.jira.issue.IssueInputParameters;
	import com.atlassian.jira.issue.customfields.view.CustomFieldParams;
	import com.atlassian.jira.issue.customfields.view.CustomFieldParamsImpl;
	import com.atlassian.jira.issue.fields.CustomField;
	import com.valiantys.nfeed.api.IFieldValueService;

	import java.util.Map;
	import java.util.Optional;

	IFieldValueService connectFieldValueService;

    public void populateFieldValueHolder(Map<String, Object> fieldValueHolder, CustomField customField, Issue sourceIssue) {
        CustomFieldParams customFieldParams = getCustomFieldParamsForConnect(sourceIssue, customField);
        fieldValueHolder.put(customField.getId(), customFieldParams);
    }

    public void populateIssueInputParameters(IssueInputParameters issueInputParameters, CustomField customField, Issue sourceIssue) {
        CustomFieldParams customFieldParams = getCustomFieldParamsForConnect(sourceIssue, customField);
        if (customFieldParams != null) {
            issueInputParameters.addCustomFieldValue(customField.getId(), (String) customFieldParams.getFirstValueForNullKey());
        }
    }

    private String getDbValue(String issueKey, String customFieldId) {
        try {
            return connectFieldValueService.getDbValue(issueKey, customFieldId);
        } catch (Throwable t) {
        }
        return null;
    }

    private Optional<String> toConnectStandardDbValue(Issue sourceIssue, CustomField customField) {
        String dbValue = getDbValue(sourceIssue.getKey(), customField.getId());
        if(dbValue != null) {
            return Optional.of(dbValue);
        }
        return Optional.empty();
    }

    private CustomFieldParams getCustomFieldParamsForConnect(Issue sourceIssue, CustomField customField) {        
        Optional<String> connectDbValue = toConnectStandardDbValue(sourceIssue, customField);
        if (connectDbValue.isPresent()) {
            CustomFieldParamsImpl paramsFromIssue = new CustomFieldParamsImpl(customField, connectDbValue.get());
            paramsFromIssue.transformObjectsToStrings(); // This allows to convert Connect DB value to Connect internal Form value
            return paramsFromIssue;
        }
        return new CustomFieldParamsImpl(customField);
    }
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.