how to map value of child node to parent node during issue creation using java

Mahesh March 10, 2020

I have a dropdown by name Domain which has values domainA, domainB, domainC.

for each value of domain, for example domainA has child with options component1, component2.

 

Schema info:

"customfield_10110": {
"required": true,
"schema": {
"type": "option-with-child",
"custom": "com.atlassian.jira.plugin.system.customfieldtypes:cascadingselect",
"customId": 10110
},
"name": "Domain",
"hasDefaultValue": false,
"operations": [
"set"
],
"allowedValues": [
{
"self": "https:/rest/api/2/customFieldOption/10009",
"value": "domainA",
"id": "10009",
"children": [
{
"self": "https:/rest/api/2/customFieldOption/10042",
"value": "Component1",
"id": "10042"
}
]
}
]
}

 

During the rest call to create issue, i am unable to map value of child to parent using java code. 

i am using below code to map value of child to parent but its not working. can anyone suggest a way to do it.

IssueInputBuilder issueBuilder = new IssueInputBuilder(projectKey, issueTypeID);

if (fieldID.equals("customfield_10110") && issueField.isRequired()) {
try {
// Get allowed value for the required field
String allowedValue = null;
for (Object object : issueField.getAllowedValues()) {
if (object instanceof CustomFieldOption) {
CustomFieldOption cfo = (CustomFieldOption) object;
allowedValue = cfo.getValue();
String id = String.valueOf(cfo.getId());
//set domain name
if(allowedValue.equalsIgnoreCase("domainA")) {
ComplexIssueInputFieldValue domain = getComplexIssueInputFieldValue(allowedValue,id);
issueBuilder.setFieldValue(fieldID, domain);
//set application name
Iterable<CustomFieldOption> child = cfo.getChildren();
Iterator itr = child.iterator();

while(itr.hasNext()) {
CustomFieldOption childField =(CustomFieldOption) itr.next();
String childValue=childField.getValue();
if(childValue.equalsIgnoreCase("Component1")) {
String childKey = String.valueOf(childField.getId());
ComplexIssueInputFieldValue app = getComplexIssueInputFieldValue(childValue,childKey);
issueBuilder.setFieldValue("customfield_10110", app);
break;
}
}
}

}
}

} catch (Exception ex) {
// Does not have allowed value
issueBuilder.setFieldValue(fieldID, "Test");
}
}

 

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events