Hi all! Cross posting here as the AI did not have ...
# general
j
Hi all! Cross posting here as the AI did not have any helpful suggestions unfortunately. I am running into an issue when programmatically creating a customer payment and I am super stuck. I am getting the error:
Copy code
INVALID_KEY_OR_REF
Invalid class reference key ERROR: Field 'entity.custentity_cclass.id' Not Found for subsidiary 2.
whenever I try to programmatically create a payment in a sandbox environment. I have tried 3 completely different ways to make the payment and all caused the same exact error:
Copy code
+---+---------------------------------------+----------------------------------------------------------------------------------+
| # | Entry point                           | Request                                                                          |
+---+---------------------------------------+----------------------------------------------------------------------------------+
| 1 | SuiteTalk REST, direct create         | POST /services/rest/record/v1/customerpayment with a JSON body                   |
| 2 | SuiteTalk REST, transform             | POST /services/rest/record/v1/invoice/{id}/!transform/customerpayment            |
| 3 | SuiteScript 2.1 RESTlet using         | Server-side, our own code, isDynamic: true, ignoreMandatoryFields: true          |
|   | record.transform() + record.save()    |                                                                                  |
+---+---------------------------------------+----------------------------------------------------------------------------------+
When I manually create the payment in the UI it works with no issues. For the setup I confirmed all of this: • OneWorld account, I'm creating the payment in subsidiary
2
. • Customer record has a custom entity field
custentity_cclass
(List/Record → Classification). It's a custom field, not the default
class
field
on the customer. • The custom entity field has nothing configured under "Validation & Defaulting" or "Sourcing & Filtering" — both tabs are empty. No default value, no formula, no source list/source from, no filtering criteria. • The customer's
custentity_cclass
value is
1
("Retail & Distributor Sales"). • Class id
1
is valid, active, assigned to subsidiary
2
, and has the "Include Children" checkbox checked on its subsidiary assignment. • Manually creating/saving a Customer Payment in the UI for this customer with the class set succeeds. • Everything is set to active - the class, the subsidiary, the customer, etc I have tried all of these ideas so far but none of them work: 1. ignoreMandatoryFields: true on record.save(). No effect. 2. enableSourcing: false — confirmed not applicable, docs say it's standard-mode only and we use isDynamic: true. 3. Explicitly setting class to '1' on the payment before save. Same error. 4. Different class assignment. Tried with a different class that's directly assigned to a child subsidiary of 2 (rather than relying on "Include Children" inheritance from 2). Same error. So the failure isn't sensitive to whether the class is inherited via the parent or assigned directly to the child. 5. Two different customform ids — both the bundle's default form and the customer's own form (the one the UI uses on a successful save). Same error on both. 6. UI parity check. Captured the actual form POST the UI sends on a successful save. Identical customer, subsidiary, class, undepfunds, payment, trandate. UI: success. Same fields via SuiteScript: failure. 7. Logged the assembled payment record before save() — subsidiary=2, class=1, entity=<customer id>, custentity_cclass=1 on the customer. Nothing obviously wrong. 8. Debugger. Can't use the SuiteScript Debugger — no role in the account has both Debug Scripts and Customer Payments permissions. Does anyone have any ideas whatsoever on anything else I can try? Or any ideas about what might be going on? I am super stuck and confused about how 3 completely different ways of programmatically creating the payment failed but the same exact payment can be created in the UI with no issues
e
Have you checked the affected GL accounts if they are available in sub 2?
j
Ooh thats a good idea, checking now
Thank you for the idea! Unfortunately I tried explicitly setting the A/R account to be the same one that autofills when I manually create the payment in the UI but got the same exact error message
Invalid class reference key ERROR: Field 'entity.custentity_cclass.id' Not Found for subsidiary 2.
Do you have any other thoughts on things I could try by any chance? Or insights into what might be going on? That custom field is only on customers according to its config and I triple checked that the customer I am using has it set to a real class object with
Include Children
checked. Thank you so much for your time!
b
you cannot set an entity field while creating a transaction
1
j
Ooh good to know, do you know how I can tell what fields are entity fields?
b
in this case, custentity is the prefix of a custom entity field
j
Hmm yeah but I'm not setting
custentity_cclass
as part of the payment (or at any point). Maybe a script is somewhere that I missed? Will double check
t
I noticed you're using is dynamic:true, the implication is that it'll function exactly the way it functions in UI So test the way everything works in UI to see if you missed anything in the script
👀 2
y
Hi Justin, are there any Access (e.g. role) restrictions on the custom entity field?
j
Good idea but unfortuntuly not, the default access level is edit and there are no roles added with special permissions. After some investigation I found a couple of workflows not visible with my developer account but visible via some suiteql queries I could make with higher permissions. I don't have permissions yet to see what they actually do (and it doesnt seem visible via suiteql) but they are named in a way that defs makes me think they are messing with classes so Im looking into that now. Thank you for the help!
youre welcome 1
j
Is that custom class already set on the customer record, and when creating the payment are you pulling the customer record on creation of the payment?
j
Very possible, I am not doing anything in the code to get the customer record info but I kinda think the workflows are doing something like this. Im still working on getting access there, Im optimistic though!
It worked!!! They turned off those workflows and I successfully saved a payment! Thank you so much for your help everyone!!
🙌🏻 1
🙌🏼 1