Hi Guys, have you ever tried transforming purchase...
# suitescript
t
Hi Guys, have you ever tried transforming purchase order to vendor bill? I have this code
Copy code
const vendorBill = record.transform({
    fromType: record.Type.PURCHASE_ORDER,
    fromId: parseInt(purchaseOrderId),
    toType: record.Type.VENDOR_BILL,
    isDynamic: true,
    defaultValues: {
        'trandate': '2023-12-31',
        'entity': parseInt(customerId),
        'postingperiod': 323,
        'subsidiary': parseInt(subsidiary),
        'duedate': dateToday,
        'currency': currency,
        'exchangerate': exchangerate,
        'location': location
    }
});
I tried to check all the variables and they all have value, but still I am having this error message "type": "error.SuiteScriptError", _"name": "INVALID_RCRD_TRANSFRM",_ "message": "You have entered an invalid default value for this record transformation operation.", "id": "",
full error message.js
n
You cannot default all those values. Go to NS help and look at N/record and the part lower down on the main page "N/record Default Values"
πŸ‘€ 1
app/help/helpcenter.nl?fid=section_4267255811.html#bridgehead_4423371543
t
Thanks, I can see it now. Based on my understanding, if I want to transform PO to VendorBill default value I need is only entity right?
After updating the code into this
Copy code
const vendorBill = record.transform({
    fromType: record.Type.PURCHASE_ORDER,
    fromId: 21953, // parseInt(purchaseOrderId),
    toType: record.Type.VENDOR_BILL,
    isDynamic: true,
    defaultValues: {
        'entity': parseInt(customerId),

    }
});

const vendorBillId = vendorBill.save({
    enableSourcing: true,
    ignoreMandatoryFields: true
});
I get this error You must enter at least one line item for this transaction
n
You probably have to do other things on the transaction before saving it such as select lines to include
s
Has that PO got any unbilled lines?
t
Yes correct @Stuart Anderton
so I added something like this before the save
Copy code
vendorBill.selectNewLine({sublistId:"item"});
vendorBill.setCurrentLineItemValue({
    sublistId:"item",
    fieldId: "item",
    value: 260,
    ignoreFieldChange: true
});
vendorBill.commitLineItem({sublistId: "item"});
Still no luck 😐
m
Try transforming a PO to bill in the UI, check the URL parameters and use those as the default values
t
Thanks @michoel, but I am not familiar on how to transform PO to vendor bill. Can you share more on how to do this. keanu thanks
m
If you open the PO in the UI there should be a button labeled Bill
t
ah I see.. Ok Ill try to check the URL parameter then
this is what I get on the URL PARAMS https://xxx.app.netsuite.com/app/accounting/transactions/vendbill.nl?*transform=purchord&whence=&id=21957&e=T&memdoc=0* and I transpose it to script like this
Copy code
const vendorBill = record.transform({
    fromType: record.Type.PURCHASE_ORDER,
    fromId: parseInt(21957),
    toType: record.Type.VENDOR_BILL,
    isDynamic: true,
    defaultValues: {
        'memdoc': parseInt(0)
    }
});

var vendorBillId = vendorBill.save();
But no luck πŸ˜“
Wait I got it!
Copy code
const vendorBill = record.transform({
    fromType: record.Type.PURCHASE_ORDER,
    fromId: parseInt(purchaseOrderId),
    toType: record.Type.VENDOR_BILL,
    isDynamic: true,
    memdoc: 0,
 });

var vendorBillId = vendorBill.save();
I've added memdoc as part of the parameter.. Thanks for the idea @michoel πŸ™‚
a
Hi @Tyn Guardian, I'm trying to do a similar thing and saw your thread. Does record.transform let you partially bill the purchase order? Or does it bill all of the items in the purchase order?
s
It creates a bill with all billable items, but you can go through and remove any you don’t want before saving.
πŸ‘ 1
t
Hi @Abhyuday Luthra Yes agree on what Stuart says. You can add and remove items you dont want to save before saving πŸ™‚
thankyou 1