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