3

I'm trying to delete a specific SalesOrderDetail record (from the id value) using the REST API.

I don't see a way to do it using the default API. I've tried customizing the Web Service Endpoint to create a top-level entity for SalesOrderDetail so that I can use the DELETE method with it, but it didn't seem to work.

I've also tried adding an action to the SalesOrder endpoint that would let me delete a row on the details, but the action isn't available for me to use and I'm not sure how to access it.

Does anyone know how this can be done?

Ethan H.
  • 116
  • 5
  • Ethan, If your problem is with code you've written, you should include some. Include just enough code to allow others to reproduce the issue. Please see [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – abestrad Feb 22 '19 at 20:15
  • @abestrad There isn't an issue with any code (yet). My question is about what endpoint to use, or how to set up a custom endpoint in the Acumatica REST API to delete a record. – Ethan H. Feb 22 '19 at 20:20

1 Answers1

7

You can delete the detail line of an item by setting the delete property of the detail entity to true. This can be done with any endpoint and here is how:

First retrieve the record with the detail you want to remove:

GET : https://localhost/MyStoreInstance/entity/Default/18.200.001/SalesOrder?$expand=Details&$select=OrderNbr,OrderType,Details/InventoryID,Details/ WarehouseID&$filter=OrderType eq 'SO' and CustomerOrder eq 'SO248-563-06'

You should get a similar result:

[
    {
        "id": "c52bd7ac-c715-4ce3-8565-50463570b7d9",
        "rowNumber": 1,
        "note": "",
        "CustomerOrder": {
        "value": "SO248-563-06"
        },
        "Details": 
        [
            {
                "id": "988988a5-3bc0-4645-a884-8a9ba6a400b4",
                "rowNumber": 1,
                "note": "",
                "InventoryID": {
                "value": "AALEGO500"},
                "WarehouseID": {"value": "MAIN"},
                "custom": {},
                "files": []
            },
            {
                "id": "983f9831-b139-489c-8ad0-86d50f6e535d",
                "rowNumber": 2,
                "note": "",
                "InventoryID": {"value": "CONTABLE1"},
                "WarehouseID": {"value": "MAIN"},
                "custom": {},
                "files": []
            },
            {
                "id": "19193380-63b2-445c-a50b-fd6d57f176a0",
                "rowNumber": 3,
                "note": "",
                "InventoryID": {"value": "CONGRILL"},
                "WarehouseID": {"value": "MAIN"},
                "custom": {},
                "files": []
            }
        ],
        "OrderNbr": {"value": "000003"},
        "OrderType": {"value": "SO"},
        "custom": {},
        "files": []
    }
]

You can then resent in a PUT request with the following body in order to delete the corresponding detail line

{
    "OrderType":{"value":"SO"},
    "OrderNbr":{"value":"000003"},
    "Hold":{"value":false},
    "Details":
    [
        {
            "id":"19193380-63b2-445c-a50b-fd6d57f176a0",
            "delete":true
        }
    ]
}
samol518
  • 1,354
  • 9
  • 8
  • Tested this and it works. This is exactly what I was looking for. I didn't know about the "delete" property. Thank you. – Ethan H. Feb 22 '19 at 22:52
  • how can i add files to a line item. – Anshu Kumar Mar 13 '19 at 06:43
  • @AnshuKumar I think this should be another question as this is not related to the topic here – samol518 Mar 14 '19 at 13:43
  • @samol518 I have created a new question for same. Here is the link for the same. https://stackoverflow.com/questions/55137176/add-files-to-salesorder-line-item – Anshu Kumar Mar 15 '19 at 03:56
  • This answer was helpful that we were able to add the delete to all rows, sent as one request, removes them all without having to iterate and delete each detail item one-by-one. (1 request instead of 12+) – Paul T. Oct 24 '19 at 02:22
  • How would you delete a file from a StockItem then? – Jebanisa May 27 '20 at 05:53