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