Create
1 min
To create a Credit Memo in NetSuite, use action as "createCreditMemo" and pass the Credit Memo data in the requestJSON under "CreditMemos".
Note: You can only create one record at a time.
The following is an example of creating a Credit Memo where we are setting every possible field (See Credit Memo for the available fields). The response will return the response back from NetSuite, which includes Credit Memo Id (internalId), plus the newly created Salesforce Credit Memo Id (salesforceID)
// Create a Map to store all the data of a CM
Map<String, Object> nsCM = new Map<String, Object>();
nsCM.put('classification', new Map<String, Object>{'internalId'=>'1'});
nsCM.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
nsCM.put('department', new Map<String, Object>{'internalId'=>'1'});
nsCM.put('location', new Map<String, Object>{'internalId'=>'10'});
nsCM.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
nsCM.put('discountRate', '-15');
nsCM.put('entity', new Map<String, Object>{'internalId'=>'109118'});
nsCM.put('memo', 'Order 250');
nsCM.put('otherRefNum', '4343399');
nsCM.put('tranDate', DateTime.newInstance(2023, 04, 26).getTime()/1000);
// 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'=>'2'});
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');
lineItem.put('item', new Map<String, Object>{'internalId'=>'9524'});
lineItem.put('quantity', 1);
lineItem.put('Amount', 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', 'custcol_checkbox');
liCustomField.put('value', 'true');
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', 'createCreditMemo');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);