7

So, this is what I'm doing (hardcoding most values for now, just trying to learn NS):

    var vendorBillPayment = record.create({
            type: record.Type.VENDOR_PAYMENT,
            isDynamic: false,
            defaultValues: {
                entity: 45
            }
        })

        vendorBillPayment.setValue({
            fieldId: 'entityname',
            value: "Superior ISP"
        })

        vendorBillPayment.setValue({
            fieldId: 'account',
            value: 129
        })

        vendorBillPayment.setValue({
            fieldId: 'currency',
            value: 1
        })

        vendorBillPayment.setValue({
            fieldId: 'customform',
            value: 45
        })

        vendorBillPayment.setValue({
            fieldId: 'exchangerate',
            value: "1.00"
        })

        var recordId = vendorBillPayment.save({
             enableSourcing: false,
             ignoreMandatoryFields: true
        })

Now, the problem begins in the snippet below, VendorPayment record has a sublist 'apply', which is a list of bills that the payment needs to apply.

        vendorBillPayment.setSublistValue({
            sublistId: 'apply',
            fieldId: 'internalid',
            line: 1,
            value: "303"
        });

The returned error is:

    error message:{"type":"error.SuiteScriptError","name":"UNEXPECTED_ERROR","message":null,"stack":["anonymous(N/recordService)","<anonymous>(/SuiteScripts/..)"],"cause":{"type":"internal error","code":"UNEXPECTED_ERROR","details":null,"userEvent":null,"stackTrace":["anonymous(N/recordService)","<anonymous>(/SuiteScripts/..)"],"notifyOff":false},"id":"","notifyOff":false}

That is, not very useful message. I've been going over their documentation, but no win.

EDIT: turns out that the apply sublist is of type list. This means, that one can NOT programmatically add/remove lines from that sublist. Just to edit the existing lines.

Is there another way to programmatically pay the vendor bill, other than creating a VENDOR_PAYMENT record?

user2187935
  • 751
  • 2
  • 8
  • 19
  • First index of a sublist in SuiteScript 2.0 is `0` not `1`; try setting `line` to `0` instead. I think you'll also need to be checking the `apply` box on the sublist line, so you'll need to set `apply` to `true` on the line as well. – erictgrubaugh Apr 01 '17 at 04:13
  • @erictgrubaugh Hi, sorry for delayed reply and thank you for a response. Now, with the regard to the question - it is not possible to do it with VENDOR_PAYMENT record on the netsuite. The reason is that the "apply" sublist is of type "list", which means you can NOT dynamically add/remove lines. You can only edit existing lines. – user2187935 Apr 06 '17 at 16:15
  • Interesting. While I haven't tried this with Vendor Payments specifically, I do know that this limitation does not exist for Customer Payments. – erictgrubaugh Apr 06 '17 at 16:31
  • @erictgrubaugh I was wondering, since you're NetSuite guru, is there another way to programmatically pay a vendor bill ? I tried first to directly set statuses on the bill record, only to quickly find that status is a read-only field. Then, I have tried VENDOR_PAYMENT approach. The other idea I have that is floating in my head is to use NS web services, but this would introduce dependencies to my system that I would rather avoid (apache axis, among others). Do you think there may be another way to pay the vendor bill? – user2187935 Apr 06 '17 at 16:41
  • I do not know of another way to do this if the `apply` sublist on the Vendor Payment is not scriptable. I don't believe it will be available in Web Services either if it's not available in SuiteScript. – erictgrubaugh Apr 06 '17 at 17:00
  • Did you found solution? I am stuck on another issue where I am getting "You have entered an Invalid Field Value 129 for the following field: account" – Ashish Gupta Jan 23 '18 at 14:29

3 Answers3

0

Its tough to be certain based on the code you provided but I see two potential issues. First off, the Apply sublist IS listed as scriptable according to NetSuite's documentation. You can see the sublist listed in the Records Browser under Vendor Payment here: https://system.na1.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/itemfulfillment.html You can also see that the 'apply' sublist is specifically called out in the list of Scriptable Sublists here: https://system.na2.netsuite.com/app/help/helpcenter.nl?fid=chapter_N3206326.html

Now on to the code issues. It is not totally clear as I stated before, but based on what you have provided above it would appear that you are attempting to add/edit the 'apply' sublist on a record after it has been saved. You will either need to add the sublist values before saving, or re-load the record before setting the sublist values. The second issue I can see is that you are attempting to set the 'internalid' of the sublist record which you cannot do. I could be wrong but I don't know of any records in NetSuite, custom or otherwise that allow the setting of the 'internalid'. I could provide more clear direction with a larger sample of the script you are trying to write, but as of now that is all that can be gleamed from your example.

Todd Grimm
  • 509
  • 1
  • 3
  • 14
0

If you are doing this all in the same script then you must reload the vendor payment before applying:

var recordId = vendorBillPayment.save({
    enableSourcing: false,
    ignoreMandatoryFields: true
});
vendorBillPayment = record.load({
    type:record.Type.VENDOR_PAYMENT,
    id:recordId
});

Also note that if you are receiving the payment against a particular bill you can do this in one step:

var vendorBillPayment = record.transform({
    fromType: 'vendorbill',
    fromId: 303,
    toType:'vendorpayment'
});
// adjust the apply lines as necessary
bknights
  • 14,408
  • 2
  • 18
  • 31
0

When creating Vendor Payment, the sublist 'apply' is dependent on the open Vendor Bills of the selected Vendor/Supplier(entity), so it is mandatory that you need to set the Vendor/Supplier(entity) first(which is what you are doing). Having said that, you cannot add/pay a Vendor Bill that doesn't have a status of 'Open' on the Vendor Payment. If you don't see a Vendor Bill in the 'apply' sublist that means that the Vendor Bill is not yet Approved or the amount of it is zero. You want to make sure that the Vendor Bills you want to pay are approved or has a status of 'Open'.

vVinceth
  • 905
  • 5
  • 7