Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

CustomerRequestService createCustomerRequest () return error for selects field

Suresh Sakhare September 24, 2017

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

1 accepted

5 votes
Answer accepted
Anuj Sapate October 2, 2017

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.

Suresh Sakhare
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.
October 3, 2017

Thanks Anuj.

It will work for me.

2 votes
Anuj Sapate October 2, 2017

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. 

1 vote
Maarten Cautreels
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.
September 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 Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events