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
1// Create a Map to store all the data of a CM
2Map<String, Object> nsCM = new Map<String, Object>();
3 nsCM.put('internalId', '121563');
4 nsCM.put('classification', new Map<String, Object>{'internalId'=>'4'});
5 nsCM.put('department', new Map<String, Object>{'internalId'=>'3'});
6 nsCM.put('location', new Map<String, Object>{'internalId'=>'10'});
7 nsCM.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
8 nsCM.put('discountRate', '-20');
9 nsCM.put('entity', new Map<String, Object>{'internalId'=>'362'});
10 nsCM.put('memo', 'Order 300');
11 nsCM.put('otherRefNum', '4343390');
12 nsCM.put('tranDate', DateTime.newInstance(2023, 09, 07).getTime()/1000);
13
14// apply only to Approved status containing invoices and having same customer as credit memo
15 List<Object> creditMemoApplyList = new List<Object>();
16 Map<String,Object> apply = new Map<String,Object>();
17 apply.put('doc', '131747');
18 apply.put('line', '0');
19 apply.put('apply',true);
20 creditMemoApplyList.add(apply);
21 nsCM.put('applyList', new Map<String,Object>{'apply'=>creditMemoApplyList,'replaceAll'=>false});
22
23// Initializing the CM Custom Fields
24 List<Object> cmCustomFieldList = new List<Object>();
25 Map<String,Object> cmCustomField = new Map<String,Object>();
26 cmCustomField.put('fieldType', 'select');
27 cmCustomField.put('scriptId', 'custbody_customlist');
28 cmCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'3'});
29 cmCustomFieldList.add(cmCustomField);
30
31// Adding the CM Custom Fields
32 nsCM.put('customFieldList', new Map<String,Object>{'customField'=>cmCustomFieldList});
33
34// Initializing the CM Line Items
35 List<Object> lineItemList = new List<Object>();
36 Map<String, Object> lineItem = new Map<String, Object>();
37 lineItem.put('description', 'A weapon for shooting arrows test');
38 lineItem.put('item', new Map<String, Object>{'internalId'=>'2917'});
39 lineItem.put('replaceAll', false);
40 lineItem.put('amount', 10);
41 lineItem.put('quantity', 2);
42 lineItem.put('grossAmt', 220);
43 lineItem.put('tax1Amt', 210);
44 lineItem.put('revRecEndDate', DateTime.newInstance(2023, 09, 07).getTime()/1000);
45 lineItem.put('revRecStartDate', DateTime.newInstance(2024, 09, 07).getTime()/1000);
46
47// Initializing the Line Item custom fields
48 List<Object> liCustomFieldList = new List<Object>();
49 Map<String, Object> liCustomField = new Map<String, Object>();
50 liCustomField.put('fieldType', 'boolean');
51 liCustomField.put('scriptId', 'custbody_checkbox');
52 liCustomField.put('value', 'false');
53 liCustomFieldList.add(liCustomField);
54
55// Adding the CM Line Item Custom Fields
56 lineItem.put('customFieldList',new Map<String,Object>{'customField'=>liCustomFieldList});
57 lineItemList.add(lineItem);
58
59// Adding the Line Items to CM
60 Map<String, Object> cmLineitemList = new Map<String, Object>();
61 cmLineitemList.put('item',lineItemList);
62 nsCM.put('itemList',cmLineitemList);
63
64// Initializing the RequestJSON Data to be passed.
65Map<String, Object> requestJSONMap = new Map<String, Object>();
66 requestJSONMap.put('CreditMemos', new List<Object>{nsCM});
67 String reqJSON = JSON.serialize(requestJSONMap);
68
69Map<String, Object> reqObj = new Map<String, Object>();
70 reqObj.put('version', '1.0');
71 reqObj.put('action', 'updateCreditMemo');
72 reqObj.put('requestJSON', reqJSON);
73
74// Placing a request to Breadwinner Global API
75Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
76System.debug(resp);