1// Create a Map to store all the data of a Purchase Order
2Map<String, Object> nsPurchaseorder = new Map<String, Object>();
3 nsPurchaseorder.put('classification', new Map<String, Object>{'internalId'=>'5'});
4 nsPurchaseorder.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
5 nsPurchaseorder.put('department', new Map<String, Object>{'internalId'=>'2'});
6 nsPurchaseorder.put('dueDate', DateTime.newInstance(2020, 12, 31).getTime()/1000);
7 nsPurchaseorder.put('entity', new Map<String, Object>{'internalId'=>'30440'});
8 nsPurchaseorder.put('shipTo', new Map<String, Object>{'internalId'=>'362'});
9 nsPurchaseorder.put('memo', 'PO 12');
10 nsPurchaseorder.put('otherRefNum', '4343399');
11 nsPurchaseorder.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);
12
13// Initializing the Purchase Order Custom Fields
14 List<Object> poCustomFieldList = new List<Object>();
15 Map<String, Object> poCustomField = new Map<String, Object>();
16 poCustomField.put('fieldType', 'select');
17 poCustomField.put('scriptId', 'custbody_customlist');
18 poCustomField.put('valueLookup', new Map<String, Object>{'internalId'=>'2'});
19 poCustomFieldList.add(poCustomField);
20
21// Adding the Purchase Order Custom Fields
22 nsPurchaseorder.put('customFieldList', new Map<String, Object>{'customField'=>poCustomFieldList});
23
24// Initializing the Purchase Order 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'=>'239'});
29 lineItem.put('quantity', 1);
30 lineItem.put('rate', '999');
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 Purchase Order 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 Purchase Order
45 Map<String, Object> poLineitemList = new Map<String, Object>();
46 poLineitemList.put('item', lineItemList);
47 nsPurchaseorder.put('itemList', poLineitemList);
48
49// Initializing the RequestJSON Data to be passed.
50Map<String, Object> requestJSONMap = new Map<String, Object>();
51 requestJSONMap.put('purchaseOrders', new List<Object>{nsPurchaseorder});
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', 'createPurchaseOrder');
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);