2

When I create a new Customer Refund with a selected Customer, I now get an error of INVALID_KEY_OR_REF Invalid paymentmethod reference key VISA. This code use to work before the latest 2016 R1 upgrade.

// create the Customer Refund record            
var customerRefund = nlapiCreateRecord("customerrefund", {
    entity: creditMemo.getFieldValue("entity") // preload with customer credits
});

How can I create a new Customer Refund based on the credit memos for a customer without getting this error about a payment method? I don't even see that a Credit Memo has a paymentmethod field.

Additional Info

I tried initializing the paymentmethod in the nlapiCreateRecord call, now I'm getting this error:

INVALID_RCRD_INITIALIZE You have entered an invalid default value for this
record initialize operation.
Russ Petersen
  • 765
  • 1
  • 9
  • 29
  • 1
    If you try to emulate this script manually in the GUI, e.g. create a customer refund from a credit memo screen, then set the customer to be the same, do you get any errors? – TonyH Apr 12 '16 at 23:02
  • Nope no errors, when creating a new Customer Refund it brings up the blank form, I type in the customer number and select the customer in the list, then the Credits and Deposits are listed in the Apply tab. This error is happening when a nlapiCreateRecord is called, way before the follow on nlapiSubmitRecord is called. – Russ Petersen Apr 13 '16 at 14:09
  • 1
    Is it possible that there's a another script or Workflow running when you call CreateRecord? – TonyH Apr 13 '16 at 16:13

2 Answers2

0

Refund Method (internal id of field is - paymentmethod) field exist on Customer Refund record under "Refund Method" tab and not on the credit memo record.

Since this field is mandatory so you will have to set this. You can view the internal ids of available payment methods in your NetSuite account by navigating to Accounting > Accounting Lists > New > Payment Method and than list the values of Payment method list. After this in your code you have to set field as follows -

customerRefund.setFieldValue('paymentmethod', 1); //In my account 1 is for Visa
  • I'm getting this error on the nlapiCreateRecord not the nlapiSubmitRecord. Are you saying besides pre-setting the customer I should also set the paymentmethod in the parms passed to nlapiCreateRecord? – Russ Petersen Apr 13 '16 at 14:11
0

For your nlapiCreateRecord call all you should need to supply is the customer internalid like you are doing.

If there isn't some user event script or worflow involved you might want to also include making sure the form you are using doesn't have any special requirements. In my account the following is all that is necessary to create a customer refund. The customer internal id is 996 and the target credit memo id is 1189. The customer has a default credit card and the refund picks that up automatically.

var ref = nlapiCreateRecord('customerrefund', {entity:996,customform:41});
for(var i = ref.getLineItemCount('apply'); i>0; i--){
    if(1189 == ref.getLineItemValue('apply', 'doc', i)){
    ref.setLineItemValue('apply', 'apply', i, 'T');
    ref.setLineItemValue('apply', 'amount', i, ref.getLineItemValue('apply', 'due', i));
}
console.log(
i +' '+
ref.getLineItemValue('apply', 'doc', i) +' '+ 
ref.getLineItemValue('apply', 'apply', i) +' '+ 
ref.getLineItemValue('apply', 'amount', i) + ' '+
ref.getLineItemValue('apply', 'total', i));
}
console.log(nlapiSubmitRecord(ref, true));
bknights
  • 14,408
  • 2
  • 18
  • 31