Home > Forum > Processes > API, starting new element with a ChoiceField, InvalidFieldData

API, starting new element with a ChoiceField, InvalidFieldData
0

Hi,
I am unable to figure out how to use the Webcon REST API for starting new element. My issue relates to the "ChoicePicker" / "Autocomplete" fields, where I cannot find the way to submit the value.
I think that I have tried all the combinations, but I always end up with the same error.

Public Api POST /api/data/v6.0/db/1/elements
- "formFields"[]
- "guid":"...", "value": [{"id": "115"}]
- "guid":"...", "value": [{"id": "115", "name": "ElementName"}]
- "guid":"...", "svalue": "115"
- "guid":"...", "svalue": "115", "value": [{"id": "115"}]
- "guid":"...", "svalue": "115#ElementName"
- "guid":"...", "svalue": "115#ElementName", "value": [{"id": "115"}]
- "guid":"...", "svalue": "115#ElementName", "value": [{"id": "115", "name": "ElementName"}]

Can it be caused by "scope / permission" issues? I do not have any trouble GETting elements with given IDs in API:
> Public API GET /api/data/v6.0/hightrust/db/1/elements/80 → 200 OK
> Public API GET /api/data/v6.0/hightrust/db/1/elements/115 → 200 OK
> Public API GET /api/data/v6.0/hightrust/db/1/elements/180 → 200 OK

-----------------

*Exception from administration tools*:
Public Api POST /api/data/v6.0/db/1/elements
Status code: 409 Error message: Validation error for fields:
Field FieldName1 (guid: 43e896d4-1382-4a71-83c7-333f265015e6 id: 399 has invalid value: Value with id: '115' does not exist
Field FieldName2 (guid: 8a6d26cc-4d88-40d9-b92d-8095d1946d2c id: 403 has invalid value: Value with id: '80' does not exist
Field FieldName3 (guid: d330700a-8af1-4749-98d1-e5626c248bc8 id: 406 has invalid value: Value with id: '118' does not exist

Callstack: WebCon.BPSCloud.Core.PublicApi.Exceptions.InvalidFieldDataException: Validation error for fields:
Field FieldName1 (guid: 43e896d4-1382-4a71-83c7-333f265015e6 id: 399 has invalid value: Value with id: '115' does not exist
Field FieldName2 (guid: 8a6d26cc-4d88-40d9-b92d-8095d1946d2c id: 403 has invalid value: Value with id: '80' does not exist
Field FieldName3 (guid: d330700a-8af1-4749-98d1-e5626c248bc8 id: 406 has invalid value: Value with id: '118' does not exist

at WebCon.BPSCloud.Core.PublicApi.Root.Validators.ElementsValidator.ValidateFieldsValues(InvalidFieldsCollections invalidFields)
at WebCon.BPSCloud.Core.PublicApi.Root.Managers.PublicApiFormManager.SetFormFieldsAsync(IElementForm element, NewElement model)
at WebCon.BPSCloud.Core.PublicApi.Root.Managers.PublicApiFormManager.StartNewElementAsync(Int32 dbId, String path, NewElement element)
at WebCon.BPSCloud.Portal.API.Public.v60.PublicApiElementsController.AddNewElement(Int32 dbId, String path, ApiMode mode, NewElement element)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

The following data submission format for "guid": "2a02378f-a8d3-401b-9d91-5deb62baf4c5" in the form of "svalue": "1#Invoice" or "svalue": "1" works correctly. Please check if you have any restrictions in your fields—these values must be accessible for the API account when creating/updating data.


{
"workflow": {
"guid": "6d2399bc-360c-43de-8e8b-ea5a99956de0"
},
"formType": {
"guid": "2cb6f559-f7d5-481d-9e47-967f584ded19"
},

"formFields": [
{
"guid": "2a02378f-a8d3-401b-9d91-5deb62baf4c5",
"svalue": "1"
}

]

}

In reply to: Raluca-Mirabela Lupu

Hi,
Do you have a dictionary data source associated with choicefield?
If you have a dictionary, are you giving the api permission to see the data?

Thanks,
Raluca

Thank you for your help.

The svalues were passed correctly, as I was using body of existing element fetched with GET request.
Thanks to you it turned out, that I did not grant access to the process being the source of options for the ChoicePicker.
That missing permission was surprising. I was quite used to the fact, that I can create element with body coming from GET.