Global API
...
Requests
Sales Order
Update
1min
The following is an example of update SalesOrder where we are changing some of the fields . (See SalesOrder for all available fields). The NetSuite Sales Order Id (internalId) is required to update the Sales Order.
Note: You can only update one record at a time.
The response returns the complete Sales Order 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 Sales Order
2Map<String, Object> nsSalesOrder = new Map<String, Object>();
3nsSalesOrder.put('internalId', '83943');
4nsSalesOrder.put('classification', new Map<String, Object>{'internalId'=>'2'});
5nsSalesOrder.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
6nsSalesOrder.put('department', new Map<String, Object>{'internalId'=>'1'});
7nsSalesOrder.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
8nsSalesOrder.put('discountRate', '-20');
9nsSalesOrder.put('entity', new Map<String, Object>{'internalId'=>'362'});
10nsSalesOrder.put('memo', 'Order 30');
11nsSalesOrder.put('otherRefNum', '4343390');
12nsSalesOrder.put('tranDate', DateTime.newInstance(2021, 09, 07).getTime()/1000);
13
14// Initialize the Sales Order Custom Fields
15List<Object> soCustomFieldList = new List<Object>();
16Map<String,Object> soCustomField = new Map<String,Object>();
17soCustomField.put('fieldType', 'select');
18soCustomField.put('scriptId', 'custbody_customlist');
19soCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
20soCustomFieldList.add(soCustomField);
21
22// Add the Sales Order Custom Fields
23nsSalesOrder.put('customFieldList', new Map<String,Object>{'customField'=>soCustomFieldList});
24
25// Initialize the Sales Order Line Items
26List<Object> lineItemList = new List<Object>();
27Map<String, Object> lineItem = new Map<String, Object>();
28lineItem.put('description', 'A weapon for shooting arrows test');
29lineItem.put('item', new Map<String, Object>{'internalId'=>'239'});
30lineItem.put('amount', 10);
31lineItem.put('quantity', 2);
32lineItem.put('grossAmt', 220);
33lineItem.put('tax1Amt', 210);
34lineItem.put('taxRate1', 1);
35lineItem.put('revRecEndDate', DateTime.newInstance(2021, 09, 07).getTime()/1000);
36lineItem.put('revRecStartDate', DateTime.newInstance(2021, 09, 07).getTime()/1000);
37
38
39// Initialize the Line Item custom fields
40List<Object> liCustomFieldList = new List<Object>();
41Map<String, Object> liCustomField = new Map<String, Object>();
42liCustomField.put('fieldType', 'boolean');
43liCustomField.put('scriptId', 'custbody_checkbox');
44liCustomField.put('value', 'true');
45liCustomFieldList.add(liCustomField);
46
47// Addg the Sales Order Line Item Custom Fields
48lineItem.put('customFieldList',new Map<String,Object>{'customField'=>liCustomFieldList});
49lineItemList.add(lineItem);
50
51// Addg the Line Items to Sales Order
52Map<String, Object> soLineitemList = new Map<String, Object>();
53soLineitemList.put('item',lineItemList);
54soLineitemList.put('replaceAll', false);
55 nsSalesOrder.put('itemList',soLineitemList);
56
57// Initialize the RequestJSON Data to be passed.
58Map<String, Object> requestJSONMap = new Map<String, Object>();
59requestJSONMap.put('salesOrders', new List<Object>{nsSalesOrder});
60String reqJSON = JSON.serialize(requestJSONMap);
61
62Map<String, Object> reqObj = new Map<String, Object>();
63reqObj.put('version', '1.0');
64reqObj.put('action', 'updateSalesOrder');
65reqObj.put('requestJSON', reqJSON);
66
67// Place a request to Breadwinner Global API
68Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
69System.debug(resp);