Basically I need to be able to create new entries in a lookup table. I’ve tried using the _api/ProjectServer/LookupTables('{tableid}')/Entries/Add
endpoint and it does somewhat work, but due to the fact that i have to set the SortIndex
upon creation, i get duplicate values on that property after the entry has been successfully created, leading to error on subsequent requests.
I’ve found an answer to another question that described the following workflow for creating new entries:
- Get all existing entries
- Sort the entries by
FullValue
- Assign a new incrementing
SortIndex
- Update the changed items/create the new one
The description was for usage with CSOM, though.
Now i tried to implement this behaviour with batch requests. Switching two items and creating a new one in the same request worked. But when it comes to the above workflow that would change around 160 items the API just returns a 200
response with the following body
--batchresponse_some_guid--
The request has the following structure:
batch_guid
Content-Type: multipart/mixed; boundary=changeset_guid
--changeset_guid
Content-Type: application/http
Content-Transfer-Encoding: binary
PATCH https://myurl/site/_api/ProjectServer/LookupTables('{tableid}')/Entries('{entryId}') HTTP/1.1
Content-Type: application/json
{ "Description": "...", "SortIndex": "1" }
--changeset_guid
Content-Type: application/http
Content-Transfer-Encoding: binary
PATCH https://myurl/site/_api/ProjectServer/LookupTables('{tableid}')/Entries('{entryId}') HTTP/1.1
Content-Type: application/json
{ "Description": "...", "SortIndex": "3" }
// Some more PATCH requests
// ...
--changeset_guid
Content-Type: application/http
Content-Transfer-Encoding: binary
POST https://myurl/site/_api/ProjectServer/LookupTables('{tableid}')/Entries/Add HTTP/1.1
Content-Type: application/json
{
"parameters":
{
"Description": "...",
"SortIndex": "2";
"ParentId": "...",
"Value": { "TextValue": "Value" }
}
}
--changeset_guid--
--batch_guid--
Am i missing something here or is there possibly a better way for creating new entries?