Global API
...
Requests
Invoice
Update
1min
The following is an example of update Invoice where we are changing some of the fields. (See Invoice for all available fields). The NetSuite Invoice Id (internalId) is required to update the Invoice.
Note: You can only update one record at a time.
The response returns the complete Invoice 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 Invoice
2Map<String, Object> nsInvoice = new Map<String, Object>();
3 nsInvoice.put('internalId', '91404');
4 nsInvoice.put('classification', new Map<String, Object>{'internalId'=>'2'});
5 nsInvoice.put('department', new Map<String, Object>{'internalId'=>'1'});
6 nsInvoice.put('memo', 'Invoice 215');
7 nsInvoice.put('otherRefNum', '4343400');
8 nsInvoice.put('tranDate', DateTime.newInstance(2020, 10, 07).getTime()/1000);
9// Initializing the Invoice Custom Fields
10 List<Object> invCustomFieldList = new List<Object>();
11 Map<String,Object> invCustomField = new Map<String,Object>();
12 invCustomField.put('fieldType', 'boolean');
13 invCustomField.put('scriptId', 'custbody_checkbox');
14 invCustomField.put('value', 'true');
15 invCustomFieldList.add(invCustomField);
16
17// Adding the Invoice Custom Fields
18 nsInvoice.put('customFieldList', new Map<String,Object>{'customField'=>invCustomFieldList});
19
20 // Initializing the Invoice Line Items
21 List<Object> lineItemList = new List<Object>();
22 Map<String, Object> lineItem = new Map<String, Object>();
23 lineItem.put('description', ' For shooting arrows');
24 lineItem.put('line', 1); // updates the existing line item with line number as 1.
25 lineItem.put('quantity', 6);
26 lineItem.put('revRecEndDate', DateTime.newInstance(2021, 09, 07).getTime()/1000);
27 lineItem.put('revRecStartDate', DateTime.newInstance(2021, 09, 07).getTime()/1000);
28// Initializing the Line Item custom fields
29 List<Object> liCustomFieldList = new List<Object>();
30 Map<String, Object> liCustomField = new Map<String, Object>();
31 liCustomField.put('fieldType', 'boolean');
32 liCustomField.put('scriptId', 'custcol_checkbox');
33 liCustomField.put('value', 'false');
34 liCustomFieldList.add(liCustomField);
35
36// Adding the Invoice Line Item Custom Fields
37 lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
38 lineItemList.add(lineItem);
39// Adding Another Line Item
40 lineItem = new Map<String, Object>();
41 lineItem.put('item', new Map<String, Object>{'internalId'=>'444'});
42 lineItem.put('quantity', 4);
43 lineItem.put('price', new Map<String, Object>{'internalId'=>'2'});
44 lineItemList.add(lineItem);
45
46// Adding the Line Items to Invoice
47 Map<String, Object> invLineitemList = new Map<String, Object>();
48 invLineitemList.put('item', lineItemList);
49 invLineitemList.put('replaceAll', false);
50 nsInvoice.put('itemList', invLineitemList);
51
52// Initializing the RequestJSON Data to be passed.
53Map<String, Object> requestJSONMap = new Map<String, Object>();
54 requestJSONMap.put('invoices', new List<Object>{nsInvoice});
55 String reqJSON = JSON.serialize(requestJSONMap);
56
57Map<String, Object> reqObj = new Map<String, Object>();
58 reqObj.put('version', '1.0');
59 reqObj.put('action', 'updateInvoice');
60 reqObj.put('requestJSON', reqJSON);
61
62// Placing a request to Breadwinner Global API
63Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
64System.debug(resp);