CustomerRequestService createCustomerRequest () return error for selects field Edited

Hi, 

I am creating customer request using jsd api. I am facing problem while setting list of fileds value. Basicaly for customField which is single select.

return error messages: Unable to to create request because of theses errors : Field with id 'customfield_10009' named 'Country' has these errors : Could not find valid 'id' or 'value' in the Parent Option object.

 

Here is my implementation.

HashMap<FieldId,FieldInputValue> map = new HashMap<FieldId, FieldInputValue>();
Either<AnError, ServiceDesk> sd = serviceDeskService.getServiceDeskById(admin, portalID);
ServiceDesk serviced = sd.getOrNull();
FieldInputValue fVlaue;
for (FieldBean fieldBean : fieldb) {
FieldId fID = FieldId.withId(fieldBean.getFieldID());
CustomField cf = customFieldManager.getCustomFieldObject(fieldBean.getFieldID());

if (!fieldBean.getValues().isEmpty()) { // select dropdown
FieldId fdid = FieldId.withId(fieldBean.getValue());
fVlaue = FieldInputValue.withValue(fdid);
}else{//text field
fVlaue = FieldInputValue.withValue(fieldBean.getValue());
}
map.put(fID, fVlaue);
}
Optional<Set<String>> user = Optional.empty();

CustomerRequestCreateParameters reqBuilder = customerRequestService.newCreateBuilder()
.serviceDesk(serviced)
.requestType(rqType)
.fieldValues(map)
.customerRequestChannelSource(CustomerRequestChannelSource.PORTAL)
.raiseOnBehalfOf(customer.getName())
.requestParticipants(user)
.build();


Either<AnError, CustomerRequest> createdRequest = customerRequestService.createCustomerRequest(admin, reqBuilder);

 

Please help me on this.

 

 

 

 

3 answers

2 accepted

I'm assuming that you're using a single select list and finding difficulties to set the value for that.

So, here is the solution for that.

Wrap the required value into the Object and set it to FieldInputValue like this:

Map<String, String> mCountry = new HashMap<String, String>();
mCountry.put("value", "India");
/*OR mCountry.put("id", "10001");*/
FieldId fd = FieldId.withId("customfield_10009");
FieldInputValue fv = FieldInputValue.withValue(mCountry);

 As per the documentation, we can set the value for single select with two different ways.

"customfield_11449" : { "value": "option3" }

or

"customfield_11449" : { "id": 10112 }

Ref: https://developer.atlassian.com/cloud/jira/service-desk/rest/

I have tested this code and works fine for me. 

I am assuming that you're using a single select list and finding difficulties to set values for that custom field while creating the customer request.

So, here is the answer for that:

Map<String, String> mCountry = new HashMap<String, String>();
/*mCountry.put("value", "India");*/
mCountry.put("id", "10001");
FieldId fd = FieldId.withId("customfield_10009");
FieldInputValue fv = FieldInputValue.withValue(mCountry);

 As per the documentation, we can set the values in two different ways:

"customfield_11449" : { "value": "option3" }

or

"customfield_11449" : { "id": 10112 }

Ref: REST APIs > Field Formats

I have tested this code and it works fine for me.

Thanks Anuj.

It will work for me.

1 vote
Maarten Cautreels Community Champion Sep 24, 2017

Hi Suresh,

I've put your code sample in the Code block to make it a bit more readable. Just to make sure if everything still looks correct, can you take a look at the code sample again.

Thanks,

Maarten

Suggest an answer

Log in or Join to answer
Community showcase
Teodora [Botron]
Published Feb 15, 2018 in Marketplace Apps

Jira Inferno: The Nine Circles of Jira Administration Hell

If you spend enough time as a Jira admin - whether you are managing a single, mid-sized instance, a large enterprise one or juggling multiple instances at once - you will eventually find yourself in ...

1,230 views 6 19
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot