It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

1 accepted

2 votes
Answer accepted

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.

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

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
Community showcase
Posted in Jira Service Desk

Tell us how you've implemented Change Management

Hello Community 👋, I'm a product manager at Atlassian, looking at improving change management capabilities across our products. In particular, we're looking at bridging the gap between Dev & ...

329 views 0 6
Join discussion

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you