I'm trying to transfrom a sales order to a cash sa...
# suitescript
s
I'm trying to transfrom a sales order to a cash sale, but it keeps erroring on the below code. I am getting an unexpected_error. Has anyone ran into this issue before? fyi: It works from the UI
Copy code
var invoiceObj = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: i_so_id,
    toType: record.Type.CASH_SALE,
    isDynamic: true
});
s
try turning off dynamic mode?
m
Are you sure that is a valid transformation? It doesn't sound like one. In other words...Sales Order and Cash Sale are kind of synonymous transaction types, the only difference is how payments occur. Transformations don't work that I know of between transactions like this, but rather creating another transaction like an Invoice from a Sales Order.
Ignore my comment. It is a valid type.
What is the error your getting?
c
I'd check your IDs. Unexpected Error typically means you did something stupid and netsuite doesn't know how to handle it. May be the ID is bad for the Sales Order. Would def try removing dynamic mode.
m
I agree with @creece. Add this before the transformation.
Copy code
log.debug({title: "SALES_ORDER_ID_AUDIT", details: i_so_id});
s
So the ID is correct. I did the log and it is correct. The SO is the correct id and turning dynamic false doesn't fix it. I even just did a record.transform() record.safe() and it still errors with "unexpected error"
It doesn't error until "save" is called
m
Check what other scripts operate on the Cash Sale. I have had errors cascade from other scripts to tranformations.
s
Copy code
var invoiceObj = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: i_so_id,
    toType: record.Type.CASH_SALE,
    isDynamic: true
});
log.debug("stuff", {
    createdfrom: invoiceObj.getValue("createdfrom"),
    customform: invoiceObj.getValue("customform")
})
invoiceObj.save();
all of it logs the expected info
Removed all scripts and it still errored
s
also try making the
i_so_id
explicitly a string or an integer
m
Might want to change save to be the following just in case.
Copy code
invoiceObj.save({ignoreMandatoryFields: true});
s
Tried that already Marvin 😕
@Sandii setting it to a string or number didn't work either 😕
s
My only other guess is there is some specific defaultValue you need to set when doing the transform
s
@creece hardcoded the created from id and set isDynamic false & true and both resulted in the same "unexpected error" when calling .save()
m
Per @Sandii you might want to try explicitly set entity.
Copy code
var invoiceObj = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: i_so_id,
    toType: record.Type.CASH_SALE,
    isDynamic: true,
    defaultValues: {
        entity: entity_id
    }
});
I would do the tranformation in the UI and check the URL for any default variables.
s
s
certainly worth a try
s
@Marvin If I set anything as a default, entity, itemship, etc it gives the error
Copy code
ou have entered an invalid default value for this record transformation operation
m
Comment out each and see which it is.
s
Both did it. I tried them individually
m
That's weird
entity
is documented as available as a default value.
s
agreed!
Copy code
var invoiceObj = record.transform({
    fromType: record.Type.SALES_ORDER,
    fromId: '36745',
    toType: record.Type.CASH_SALE,
    isDynamic: true,
    defaultValues: {
        entity: '4687'
    }
});
e
Permissions?
s
it's a map/reduce running as admin. Plus it works on some and not on others
e
Memorized transactions?
s
It doesn't say memorized on the IF or sales order
m
If it works on some and not others. Sounds like it's not the syntax of the code. Do you have multiple subsidiaries?
s
Nope, just 1 😕
c
If you aren't already, then if you're transforming it in dynamic mode, then you'd need to set whatever fields you need to set in the UI on the Cash Sale before saving. I would honestly take that out of the equation and see if you can do a transform and save without doing anything other than the transform.
i know it isn't the reason necessarily but i'd just start with basic step 1 and add stuff back in till it errors and you can track it down.
e
order status?
s
@creece that's what I've been testing with. A straight transform followed by a save. Still gives an unexpected_error
@Eric B the status is pending billing/partially recieved
Both fail @creece
c
Did you try ignoreMandatoryFields: true for the save yet?
s
Yup
c
is there a script on the cash sale doing something?
s
I disabled all of them and ran it and still got it lol. Same with workflows
Could the SO being in a closed period matter? I mean the cash sale would be in an open period
e
SOs don't have GL impact
s
For some reason I have to set the "paymentoperation" even though it's set on the sales order 🤦🏼‍♂️
s
did anyone mention backordered? pretty sure cash sale do inventory on the same step, so if back ordered, it'll be blocked??