Update
1 min
The following is an example of update Customer Payment where we are changing some of the fields. (See Customer Payment for all available fields). The NetSuite Customer Payment Id (internalId) is required to update the Customer Payment.
Note: You can only update one record at a time.
The response returns the complete Customer Payment information, but we have shortened the response in our example for ease of reading.
//Create a Map to store all the data of a Payment
Map<String, Object> nsCustomerPayment = new Map<String, Object>();
nsCustomerPayment.put('internalId', '97006');
nsCustomerPayment.put('classification', new Map<String, Object>{'internalId'=>'2'});
nsCustomerPayment.put('department', new Map<String, Object>{'internalId'=>'1'});
nsCustomerPayment.put('memo', 'Payment 25 update');
nsCustomerPayment.put('tranDate', DateTime.newInstance(2020, 11, 07).getTime()/1000);
nsCustomerPayment.put('payment', '91000');
// apply only to Approved status containing invoices and having same customer as payment
List<Object> paymentApplyList = new List<Object>();
Map<String,Object> apply = new Map<String,Object>();
apply.put('doc', '97807');
apply.put('line', '0');
apply.put('apply',true);
paymentApplyList.add(apply);
nsCustomerPayment.put('applyList', new Map<String,Object>{'apply'=>paymentApplyList,'replaceAll'=>false});
// Initializing the Payment Custom Fields
List<Object> paymentCustomFieldList = new List<Object>();
Map<String,Object> paymentCustomField = new Map<String,Object>();
paymentCustomField.put('fieldType', 'select');
paymentCustomField.put('scriptId', 'custbody_customlist');
paymentCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'1'});
paymentCustomFieldList.add(paymentCustomField);
// Adding the Payment Custom Fields
nsCustomerPayment.put('customFieldList', new Map<String,Object>{'customField'=>paymentCustomFieldList});
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('customerPayments', new List<Object>{nsCustomerPayment});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'updateCustomerPayment');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);