Hi, can anyone help me with creating a VendorBill ...
# beginners
b
Hi, can anyone help me with creating a VendorBill record from a RESTLet? Sample code in the thread.
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType Restlet
 */
define(['N/record', 'N/error'],
  function (record, error) {

    function post(context) {

      // Initialize a new vendor bill record
      var vendorBillRec = record.create({
        type: record.Type.VENDOR_BILL,
        isDynamic: false
      });

      vendorBillRec.setValue({
        fieldId: 'account',
        value: context.account
      })

      vendorBillRec.setValue({
        fieldId: 'entity',
        value: context.entity
      })

      vendorBillRec.setValue({
        fieldId: 'exchangerate',
        value: context.exchangerate
      })

      vendorBillRec.setValue({
        fieldId: 'terms',
        value: context.terms
      })

      vendorBillRec.setValue({
        fieldId: 'usertotal',
        value: context.usertotal
      })
      vendorBillRec.setValue({
        fieldId: 'approvalstatus',
        value: context.approvalstatus
      })

      var expense = context.expense;

      vendorBillRec.setSublistValue({
        sublistId: 'expense',
        fieldId: 'account',
        line: 1,
        value: expense.account
      })

      log.debug('amount', expense.amount);
      vendorBillRec.setSublistValue({
        sublistId: 'expense',
        fieldId: 'amount',
        line: 1,
        value: parseFloat(expense.amount)
      })

      vendorBillRec.setSublistValue({
        sublistId: 'expense',
        fieldId: 'memo',
        line: 1,
        value: expense.memo
      })

      vendorBillRec.setSublistValue({
        sublistId: 'expense',
        fieldId: 'custcol_scm_lc_autocalc',
        line: 1,
        value: expense.custcol_scm_lc_autocalc
      })

      var recId = vendorBillRec.save({
        enableSourcing: true,
        ignoreMandatoryFields: false
      });

      return JSON.stringify(recId);

    }

    return {
      post: post
    };
  }
);
I’m getting
error.SuiteScriptError
with message
Please enter value(s) for: Amount
s
also, you probably don't need to JSON.stringify() the
recId
before returning it
b
Ya, it did work without JSON.stringify(). I guess it is a good practice as the value being returned won’t always be a string. Let me know if I’m wrong.