I've never tried patching with an empty set, according to the OData specification, since there is no way to say that a set can't be empty, that would be valid albeit it I'd argue that a hierarchy without elements isn't really a hierarchy now is it ;-?
So, case 1; Yes, specifying an empty set '[]', would indeed remove all elements
case 2; No, you MUST NOT remove all elements first, just specifying [4, 5, 6, ..., 1000] would remove the first 3 indeed. If you removed all elements first and then added [4, 5, 6, ..., 1000] again these elements would be considered new elements and you would have lost all data associated to those elements previously!!!
------------------------------
Hubert Heijkers
------------------------------
Original Message:
Sent: Tue July 21, 2020 05:06 AM
From: Vinoth Kumar Ravi
Subject: DELETE operation on collection of ENTITY
I'm not quite sure if I understood your point correctly. Let's say I have a dimension with {1, 2, 3, 4, ...., 1000}
Case 1: If I plan to delete all the elements:
I can PATCH a null set ({}) to the Hierarchy entity for deleting all the elements.
Case 2: If I plan on deleting only few elements (say {1, 2, 3})
Do you suggest to PATCH a null set first and then PATCH {4, 5, 6, ...., 1000}
-> I also wanted a way to delete a set of elements (not all the elements), hope I will have to wait for v4.01
I meant I will have to wait for the DELETE operation to work (as it will be available in v4.01).. apologies for the confusion here.
------------------------------
Vinoth Kumar Ravi
Original Message:
Sent: Tue July 21, 2020 04:51 AM
From: Hubert Heijkers
Subject: DELETE operation on collection of ENTITY
Hi Vinoth,
I presume you meant to say you hope you will NOT have to wait for v4.01, but chances are you will (albeit we have already adopted a couple of things, like a minimal implementation of the JSON based $batch support, in TM1 already;-).
Again, PATCHing with the set of elements after deleting the set you wanted to get rid off will do the trick here as well ;-)
Cheers,
------------------------------
Hubert Heijkers
Original Message:
Sent: Tue July 21, 2020 04:20 AM
From: Vinoth Kumar Ravi
Subject: DELETE operation on collection of ENTITY
Hi Hubert,
Hope you are doing good. Thank you for all your work and contributions!
Coming back to your answer, makes sense to PATCH the entire entity. I also wanted a way to delete a set of elements (not all the elements), hope I will have to wait for v4.01
Thank you again.
------------------------------
Vinoth Kumar Ravi
Original Message:
Sent: Tue July 21, 2020 03:23 AM
From: Hubert Heijkers
Subject: DELETE operation on collection of ENTITY
Hi Vinoth,
Correct, and as the error expresses, DELETE is not defined as an operation on collection valued [navigation] properties (read: can't call delete on collections of anything). FYI, TM1's REST API follows the v4.0 OData specification for its implementation and, no surprise, DELETE is not specified for collections (note: this is changing in the pending v4.01 release of the OData specification which TM1 most likely will pick up in its next major release).
However, for your case, and many others, there is a relatively simple workaround if you want to replace the whole collection, you'd simply PATCH the container of the collection, in this case the Hierarchy entity, and only specify the Elements property. This will REPLACE the collection of elements with the one you'd specify in your request. And since I'm presuming you would want to specify new elements anyway, as a hierarchy without element, well, isn't really a hierarchy of anything, you'd have both operations done in one request.
------------------------------
Hubert Heijkers
Original Message:
Sent: Mon July 20, 2020 04:09 AM
From: Vinoth Kumar Ravi
Subject: DELETE operation on collection of ENTITY
Hello,
I tried to perform a DELETE operation for all elements in a dimension and received an error. Is collection delete not possible?
URL: https://adminhost:port/api/v1/Dimensions('test')/Hierarchies('test')/Elements
Error: DELETE not allowed on a contained collection valued navigation property!
------------------------------
Vinoth Kumar Ravi
------------------------------
#PlanningAnalyticswithWatson