has anyone successfully created/updated apply subl...
# suitetalkapi
j
has anyone successfully created/updated apply sublists on credit memos using REST? i’m having difficulty setting item amounts/apply and i’m not sure my api calls are correct. ideally, i’d like to transform an invoice into a credit memo using this call:
Copy code
POST {{REST_SERVICES}}/record/v1/invoice/1/!transform/creditmemo
or create a new credit memo:
Copy code
POST {{REST_SERVICES}}/record/v1/creditmemo
with the following payload, e.g.
Copy code
{
    "externalId": "CM-test",
    "tranDate": "2021-01-01",
    "item": {
        "items": [
            {
                "amount": 0.01,
                "item": {
                    "id": "1"
                }
            }
        ]
    }
and then auto-apply the amount to that specific invoice. however it’s unclear to me how to do this. for a few reasons: 1. when transforming, item + apply are automatically set to the full amount. 2. i can’t set or patch the record to apply: null 3. i can’t modify the apply sublist at all any help would be much appreciated!
b
which of the operations specified in Working with Sublists have you tried?
j
i’ve tried nullifying the apply sublist using PATCH and:
Copy code
{
  "apply": {
    "items": null
  }
}
or
Copy code
{
  "apply": null
}
i get this error:
Copy code
Invalid value for the resource or sub-resource field 'apply'. Provide a valid value.
for the latter, i receive the header back:
Copy code
Unknown field name apply. Field does not exist on this record instance.
i’ve also tried updating the first line of the apply items sublist using PATCH:
Copy code
{
  "apply": {
    "items": [
      {
        "line": 0,
        "apply": false
      }
    ]
  }
}
and i receive:
Copy code
"Error while accessing a resource. You have attempted an invalid sublist or line item operation. You are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist."
b
that help link is about keyed sublists and the parameter required to manipulate them
i see no keyed sublist
nor the replacement related parameter
j
ah i see. so the items on apply in a credit memo is an unkeyed sublist? and i see
Copy code
Operations 2.a, 2.b, 2.c, 3.a, 3.b, and 4 are not possible on non-keyed sublists
so this would not be possible. i would have to replace the apply sublist wholesale
b
they usually are keyed if you are transforming from something
im saying that your attempts dont use keys
nor do you note the replcement parameter
suggesting you dont know how to work with keyed sublists and should try that help link
j
thanks for the link. is the line number not the key? and in the above example, the replacement field is changing apply: true to apply: false? i also took the exact result for line 0 from a GET, and used that to run a patch, only changing apply to false, like so:
Copy code
{
  "apply": {
    "items": [
      {
        "amount": 0.01,
        "apply": false,
        "applyDate": "2020-04-03",
        "createdFrom": "1",
        "currency": "US Dollar",
        "due": 0.01,
        "line": 0,
        "refNum": "INV1",
        "total": 0.01,
        "type": "Invoice"
      }
    ]
  }
}
but received the same invalid sublist operation. not sure if the documentation implies only one field can be replaced at a time
i noticed that the apply sublist:
Copy code
{{REST_SERVICES}}/record/v1/creditmemo/eid:CM-test/apply?expandSubResources=true
returns
"links": []
, while the item sublist:
Copy code
{{REST_SERVICES}}/record/v1/creditmemo/eid:CM-test/item?expandSubResources=true
contains links to each item. i’m wondering if that suggests one can’t update individual line items on the apply sublist
b
usually working with sublists involves figuring out which field is being used as the key
usually i just try to update a single line by updating a field like amount
and then matching one other field at a time until i find what the key is
fair chance its not the line
apply sublists tend to have multiple lines with the same line field
j
i see, thanks for the tip. will try that out now.
yeah i see all the apply line items have the same line = 0.
in your experience, are there often multiple keys for apply sublists? i’ve tried combos of:
Copy code
"amount": 0.01,
                "createdFrom": 1,
                "refNum": "INV1",
                "type": "Invoice",
                "apply": true,
                "doc": {
                    "id": 1
                }
to no avail. i’m also aware that the api is buggy and it’s possible some calls may not work
b
If you cant find the key, the record is probably too beta
You may be able to get line field to work as a key in the case where there is only one apply line
j
i suspect that’s the case since it seems like some other operations on memos aren’t working properly
for some reason, the credit memo apply sublist gets created with a line for every invoice ever created, even if it comes from a transformation. if i can change this to only one invoice, i can try to use line