Create Sales Order
Sample Requests and Responses
The following is an example request which can be used while using ‘createSalesOrder’ action.
Request
// Create a Map to store all the data of a Sales Order
Map<String, Object> nsSalesOrder = new Map<String, Object>();
nsSalesOrder.put('classification', new Map<String, Object>{'internalId'=>'5'});
nsSalesOrder.put('currencyRecord', new Map<String, Object>{'internalId'=>'2'});
nsSalesOrder.put('department', new Map<String, Object>{'internalId'=>'2'});
nsSalesOrder.put('discountItem', new Map<String, Object>{'internalId'=>'-6'});
nsSalesOrder.put('discountRate', '-15');
nsSalesOrder.put('entity', new Map<String, Object>{'internalId'=>'362'});
nsSalesOrder.put('memo', 'Order 25');
nsSalesOrder.put('otherRefNum', '4343399');
nsSalesOrder.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);
// Initializing the Sales Order Custom Fields
List<Object> soCustomFieldList = new List<Object>();
Map<String,Object> soCustomField = new Map<String,Object>();
soCustomField.put('fieldType', 'select');
soCustomField.put('scriptId', 'custbody_customlist');
soCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
soCustomFieldList.add(soCustomField);
// Adding the Sales Order Custom Fields
nsSalesOrder.put('customFieldList', new Map<String,Object>{'customField'=>soCustomFieldList});
// Initializing the Sales Order Line Items
List<Object> lineItemList = new List<Object>();
Map<String, Object> lineItem = new Map<String, Object>();
lineItem.put('description', 'A weapon for shooting arrows');
lineItem.put('item', new Map<String, Object>{'internalId'=>'239'});
lineItem.put('quantity', 1);
lineItem.put('rate', '999');
// Initializing the Line Item custom fields
List<Object> liCustomFieldList = new List<Object>();
Map<String, Object> liCustomField = new Map<String, Object>();
liCustomField.put('fieldType', 'boolean');
liCustomField.put('scriptId', 'custbody_checkbox');
liCustomField.put('value', 'true');
liCustomFieldList.add(liCustomField);
// Adding the Sales Order Line Item Custom Fields
lineItem.put('customFieldList',new Map<String,Object>{'customField'=>liCustomFieldList});
lineItemList.add(lineItem);
// Adding the Line Items to Sales Order
Map<String, Object> soLineitemList = new Map<String, Object>();
soLineitemList.put('item',lineItemList);
nsSalesOrder.put('itemList',soLineitemList);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('salesOrders', new List<Object>{nsSalesOrder});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'createSalesOrder');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);
Response
{
action=createSalesOrder,
timestamp=1606471494020,
validRequest=true,
version=1.0,
responseJSON={
"status": "200",
"errors": [],
"salesOrders": [
{
"tranId": "12320000000000117",
"tranDate": 1599417000,
"total": 984.0,
"taxTotal": 0.0,
"subTotal": 999.0,
"subsidiary": {
"type": null,
"name": "Parent Company",
"internalId": "1",
"externalId": null
},
"status": "Pending Approval",
"shippingCost": null,
"salesRep": null,
"salesforceID": "a0D2w0000092RCKEA2",
"otherRefNum": "4343399",
"nullFieldList": null,
"memo": "Order 25",
"location": null,
"lastModifiedDate": 1606471491,
"itemList": {
"replaceAll": null,
"item": [
{
"unitsDisplay": null,
"taxRate1": "0.0",
"taxCode": {
"type": null,
"name": "VAT_IN:UNDEF-IN",
"internalId": "5",
"externalId": null
},
"tax1Amt": 0.0,
"shipMethod": null,
"shipGroup": null,
"serialNumbers": null,
"revRecStartDate": null,
"revRecSchedule": null,
"revRecEndDate": null,
"rate": "999.00",
"quantityRemaining": null,
"quantityReceived": null,
"quantityBilled": 0.0,
"quantity": 1.0,
"price": {
"type": null,
"name": null,
"internalId": "-1",
"externalId": null
},
"poNum": null,
"orderLine": null,
"onHand": null,
"location": null,
"line": 1,
"jobName": null,
"itemReceive": null,
"itemName": null,
"itemIsFulfilled": null,
"item": {
"type": null,
"name": "Bow",
"internalId": "239",
"externalId": null
},
"grossAmt": 999.0,
"expectedReceiptDate": null,
"description": "A weapon for shooting arrows",
"department": null,
"customFieldList": {
"customField": [
{
"valueLookup": null,
"value": "1",
"scriptId": "custcol_gh_line_no",
"internalId": "175",
"fieldType": null
},
{
"valueLookup": null,
"value": "12320000000000117_72960",
"scriptId": "custcol_gh_so_line_id",
"internalId": "200",
"fieldType": null
},
{
"valueLookup": null,
"value": "false",
"scriptId": "custcol_checkbox",
"internalId": "443",
"fieldType": null
}
]
},
"createPo": "_dropShipment",
"costEstimateType": null,
"costEstimate": null,
"classification": null,
"amount": 999.0
}
]
},
"internalId": "54352",
"handlingCost": null,
"externalId": null,
"exchangeRate": 1.0,
"entity": {
"type": null,
"name": "21 Atherton Grocery",
"internalId": "362",
"externalId": null
},
"discountTotal": -15.0,
"discountRate": "-15.00",
"discountItem": {
"type": null,
"name": "Partner Discount",
"internalId": "-6",
"externalId": null
},
"department": {
"type": null,
"name": "Sales",
"internalId": "2",
"externalId": null
},
"customForm": {
"type": null,
"name": "Custom Sales Order 2",
"internalId": "121",
"externalId": null
},
"customFieldList": {
"customField": [
{
"valueLookup": {
"type": null,
"name": "B",
"internalId": "2",
"externalId": null
},
"value": null,
"scriptId": "custbody_customlist",
"internalId": "458",
"fieldType": null
},
{
"valueLookup": null,
"value": "false",
"scriptId": "custbody_checkbox",
"internalId": "272",
"fieldType": null
}
]
},
"currencyRecord": null,
"currencyName": "US Dollars",
"createdFrom": null,
"createdDate": 1606471488,
"classification": {
"type": null,
"name": "Corporate Sales",
"internalId": "5",
"externalId": null
}
}
]
}
}