Hi, We are trying to create a vendor bill from exi...
# suitescript
p
Hi, We are trying to create a vendor bill from existing purchase order using suitescript N/record module. Following is the code:
Copy code
var vendorBill = recordModule.create({
            type: recordModule.Type.VENDOR_BILL,
            isDynamic: true,
            defaultValues: {
                entity: supplierId
            }
        });
vendorBill.selectNewLine('item');
vendorBill.setCurrentSublistValue('item', 'orderdoc', poId);
vendorBill.setCurrentSublistValue('item', 'orderline', poLineId);
                
vendorBill.commitLine('item');
vendorBill.save({
			enableSourcing: false,
			ignoreMandatoryFields: true
		});
This above code is written in a restlet and when we invoke it from postman, we get :
Copy code
{
  "type": "error.SuiteScriptError",
  "name": "YOU_CANNOT_ADD_MULTIPLE_VENDORS_ANDOR_CURRENCIES_TO_A_SINGLE_VENDOR_BILL",
  "message": "You cannot add multiple vendors and/or currencies to a single Vendor Bill.",
  "id": "",
  "stack": [
    "anonymous(N/serverRecordService)",
    "postBill(/SuiteScripts/new_post_transaction.js:1402)",
    "doPost(/SuiteScripts/new_post_transaction.js:641)"
  ],
  "cause": {
    "type": "internal error",
    "code": "YOU_CANNOT_ADD_MULTIPLE_VENDORS_ANDOR_CURRENCIES_TO_A_SINGLE_VENDOR_BILL",
    "details": "You cannot add multiple vendors and/or currencies to a single Vendor Bill.",
    "userEvent": null,
    "stackTrace": [
      "anonymous(N/serverRecordService)",
      "postBill(/SuiteScripts/new_post_transaction.js:1402)",
      "doPost(/SuiteScripts/new_post_transaction.js:641)"
    ],
    "notifyOff": false
  },
  "notifyOff": false,
  "userFacing": false
}
Please help.
@Edgar Valdes Any pointers please?
e
Check if the supplierId (the Vendor) from the Bill is the same as the vendor from the PO
💯 1
p
@Edgar Valdes Thanks for the reply. They are same. I created a new purchase order and trying to bill it using the above suitescript.
e
Why use
record.create
and not
record.transform
instead? Do you need to select some items?
p
yeah. We might have to bill multiple purchase orders in a single vendor bill and even partial item selection might be possible.
Thanks a lot for your time. I am doing hit and trial but in case something hits you please ping me, I'll give that a try.
e
You sure all the POs are from the same vendor and currency? I would add a check before. If the entity doesn 't match, or the currency doesn't match, then omit that line. Use logs to show entity and currency, check the output.
p
yeah makes sense. I'll put the logs and check once. I'll add the output here also, in case you are around and have some time, please have a look.
Hi @Edgar Valdes. You were right, The bill currency was not getting set due to some issue in my payload. I was so sure that it is correct that I never thought of logging and checking that. I logged the currencies and supplier id and found the issue. Thank you so much for your help.
✅ 1