1// Create a Map to store all the data of a CM
2Map<String, Object> nsCM = new Map<String, Object>();
3 nsCM.put('classification', new Map<String, Object>{'internalId'=>'1'});
4 nsCM.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
5 nsCM.put('department', new Map<String, Object>{'internalId'=>'1'});
6 nsCM.put('location', new Map<String, Object>{'internalId'=>'10'});
7 nsCM.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
8 nsCM.put('discountRate', '-15');
9 nsCM.put('entity', new Map<String, Object>{'internalId'=>'109118'});
10 nsCM.put('memo', 'Order 250');
11 nsCM.put('otherRefNum', '4343399');
12 nsCM.put('tranDate', DateTime.newInstance(2023, 04, 26).getTime()/1000);
13// Initializing the CM Custom Fields
14 List<Object> cmCustomFieldList = new List<Object>();
15 Map<String, Object> cmCustomField = new Map<String, Object>();
16 cmCustomField.put('fieldType', 'select');
17 cmCustomField.put('scriptId', 'custbody_customlist');
18 cmCustomField.put('valueLookup', new Map<String, Object>{'internalId'=>'2'});
19 cmCustomFieldList.add(cmCustomField);
20
21// Adding the CM Custom Fields
22 nsCM.put('customFieldList', new Map<String, Object>{'customField'=>cmCustomFieldList});
23
24// Initializing the CM Line Items
25 List<Object> lineItemList = new List<Object>();
26 Map<String, Object> lineItem = new Map<String, Object>();
27 lineItem.put('description', 'A weapon for shooting arrows');
28 lineItem.put('item', new Map<String, Object>{'internalId'=>'9524'});
29 lineItem.put('quantity', 1);
30 lineItem.put('Amount', 1000);
31
32// Initializing the Line Item custom fields
33 List<Object> liCustomFieldList = new List<Object>();
34 Map<String, Object> liCustomField = new Map<String, Object>();
35 liCustomField.put('fieldType', 'boolean');
36 liCustomField.put('scriptId', 'custcol_checkbox');
37 liCustomField.put('value', 'true');
38 liCustomFieldList.add(liCustomField);
39
40// Adding the CM Line Item Custom Fields
41 lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
42 lineItemList.add(lineItem);
43
44// Adding the Line Items to CM
45 Map<String, Object> cmLineitemList = new Map<String, Object>();
46 cmLineitemList.put('item', lineItemList);
47 nsCM.put('itemList', cmLineitemList);
48
49// Initializing the RequestJSON Data to be passed.
50Map<String, Object> requestJSONMap = new Map<String, Object>();
51 requestJSONMap.put('CreditMemos', new List<Object>{nsCM});
52 String reqJSON = JSON.serialize(requestJSONMap);
53
54Map<String, Object> reqObj = new Map<String, Object>();
55 reqObj.put('version', '1.0');
56 reqObj.put('action', 'createCreditMemo');
57 reqObj.put('requestJSON', reqJSON);
58
59// Placing a request to Breadwinner Global API
60Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
61System.debug(resp);