user2233949
user2233949

Reputation: 2233

Apply a vendor payment to an expense report in NetSuite

Is it possible to apply a vendor payment to an expense report in SuiteScript? In the UI, you can click 'Make a Payment' on the expense report, which suggested to me that you could use record.transform to transform an expense report to a vendor payment, but the documentation doesn't show that as an available transformation.

So I tried simply creating the vendor payment, and then adding the expense report to the 'Apply' sublist, but that only results in the, "... you are either trying to access a field on a non-existent line or you are trying to add or remove lines from a static sublist." error.

I have tried various methods for simply adding the expense report to the 'Apply' sublist, such as:

var rec = record.create({type: 'vendorpayment'});
rec.insertLine({sublistId: 'apply', line: 0});
rec.setCurrentSublistValue({sublistId: 'apply', fieldId: 'amount', value: "200.00"});
// More setting of the line values
rec.commitLine({sublistId: 'apply'});

...but they all seem to result in the static sublist error, which seems to suggest you can't apply a payment to an expense report that way. I've tried searching online, but haven't found an answer. Is it possible to apply a vendor payment to an expense report in SuiteScript? And if so, how?

Thanks in advance

Upvotes: 1

Views: 1186

Answers (2)

vVinceth
vVinceth

Reputation: 915

While bknights code is the correct code for tranforming transaction/record, expense report cannot be tranformed to a vendor payment via script. The type of transformation is not listed as supported transformation type, it will just throw an error "INVALID_RCRD_TRANSFRM".

If I am going to create a payment for an expense report it will be like the code below. On your sample code, you missed setting the isDynamic to true and set the entity with the default value (which is the employee). Setting isDynamic and defaultValues will return a record object with unpaid expense report for the employee, all you need to do it just iterate the apply sublist.

    var objRecord = record.create({
        type: 'vendorpayment', 
        isDynamic: true,
        defaultValues: {
            entity: idEmployee
        } 
    });
    //rest of the code goes after this line

Upvotes: 1

bknights
bknights

Reputation: 15367

when you create a bill payment in the UI you will see that the available targets for the payment are pre-created.

You cannot add new lines but have to loop through the available 'apply' lines and find the one that matches your expense report.

BTW it's better to create the payment like:

var vp = record.transform({fromType:'vendorbill', fromId:expReportInternalId, toType:'vendorpayment'});
//then you can loop through the apply lines to find the appropriate doc line:
for(var i = 0; i< vp.getLineCount({sublistId:'apply'}); i++){
    if(fromId:expReportInternalId == vp.getSublistValue({sublistId:'apply', fieldId:'doc', line:i})){
        vp.setSublistValue({sublistId:'apply', fieldId:'apply', line:i, value:true});
        ...
    }
}

Upvotes: 0

Related Questions