Global API
...
Requests
Credit Memo
Update
1min
The following is an example of updating a Credit Memo where we are changing some of the fields. (See Credit Memo for all available fields). The NetSuite Credit Memo Id (internalId) is required to update the Credit Memo.
Note: You can only update one record at a time
The response returns the complete Credit Memo information, but we have shortened the response in our example for ease of reading.
Request
Response
// Create a Map to store all the data of a CM
Map<String, Object> nsCM = new Map<String, Object>();
nsCM.put('internalId', '121563');
nsCM.put('classification', new Map<String, Object>{'internalId'=>'4'});
nsCM.put('department', new Map<String, Object>{'internalId'=>'3'});
nsCM.put('location', new Map<String, Object>{'internalId'=>'10'});
nsCM.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
nsCM.put('discountRate', '-20');
nsCM.put('entity', new Map<String, Object>{'internalId'=>'362'});
nsCM.put('memo', 'Order 300');
nsCM.put('otherRefNum', '4343390');
nsCM.put('tranDate', DateTime.newInstance(2023, 09, 07).getTime()/1000);
// apply only to Approved status containing invoices and having same customer as credit memo
List<Object> creditMemoApplyList = new List<Object>();
Map<String,Object> apply = new Map<String,Object>();
apply.put('doc', '131747');
apply.put('line', '0');
apply.put('apply',true);
creditMemoApplyList.add(apply);
nsCM.put('applyList', new Map<String,Object>{'apply'=>creditMemoApplyList,'replaceAll'=>false});
// Initializing the CM Custom Fields
List<Object> cmCustomFieldList = new List<Object>();
Map<String,Object> cmCustomField = new Map<String,Object>();
cmCustomField.put('fieldType', 'select');
cmCustomField.put('scriptId', 'custbody_customlist');
cmCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'3'});
cmCustomFieldList.add(cmCustomField);
// Adding the CM Custom Fields
nsCM.put('customFieldList', new Map<String,Object>{'customField'=>cmCustomFieldList});
// Initializing the CM Line Items
List<Object> lineItemList = new List<Object>();
Map<String, Object> lineItem = new Map<String, Object>();
lineItem.put('description', 'A weapon for shooting arrows test');
lineItem.put('item', new Map<String, Object>{'internalId'=>'2917'});
lineItem.put('replaceAll', false);
lineItem.put('amount', 10);
lineItem.put('quantity', 2);
lineItem.put('grossAmt', 220);
lineItem.put('tax1Amt', 210);
lineItem.put('revRecEndDate', DateTime.newInstance(2023, 09, 07).getTime()/1000);
lineItem.put('revRecStartDate', DateTime.newInstance(2024, 09, 07).getTime()/1000);
// Initializing the Line Item custom fields
List<Object> liCustomFieldList = new List<Object>();
Map<String, Object> liCustomField = new Map<String, Object>();
liCustomField.put('fieldType', 'boolean');
liCustomField.put('scriptId', 'custbody_checkbox');
liCustomField.put('value', 'false');
liCustomFieldList.add(liCustomField);
// Adding the CM Line Item Custom Fields
lineItem.put('customFieldList',new Map<String,Object>{'customField'=>liCustomFieldList});
lineItemList.add(lineItem);
// Adding the Line Items to CM
Map<String, Object> cmLineitemList = new Map<String, Object>();
cmLineitemList.put('item',lineItemList);
nsCM.put('itemList',cmLineitemList);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('CreditMemos', new List<Object>{nsCM});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'updateCreditMemo');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);