Create
1 min
To create an Invoice in NetSuite, use action as "createInvoice" and pass the Invoice data in the requestJSON under "invoices".
Note: You can only create one record at a time.
The following is an example of creating an Invoice, where we are setting every possible field (See for Invoice the available fields). The response will return the response back from NetSuite, which includes the new NetSuite Invoice Id (internalId), plus the newly created Salesforce Invoice Id (salesforceID)
//Create a Map to store all the data of a Invoice
Map<String, Object> nsInvoice = new Map<String, Object>();
nsInvoice.put('classification', new Map<String, Object>{'internalId'=>'5'});
nsInvoice.put('currencyRecord', new Map<String, Object>{'internalId'=>'2'});
nsInvoice.put('department', new Map<String, Object>{'internalId'=>'2'});
nsInvoice.put('entity', new Map<String, Object>{'internalId'=>'362'});
nsInvoice.put('location',new Map<String, Object>{'internalId'=>'1'});
nsInvoice.put('memo', 'Invoice 100');
nsInvoice.put('otherRefNum', '4343399');
nsInvoice.put('tranDate', DateTime.newInstance(2020, 09, 07).getTime()/1000);
// Initializing the Invoice Custom Fields
List<Object> invCustomFieldList = new List<Object>();
Map<String,Object> invCustomField = new Map<String,Object>();
invCustomField.put('fieldType', 'select');
invCustomField.put('scriptId', 'custbody_customlist');
invCustomField.put('valueLookup', new Map<String,Object>{'internalId'=>'2'});
invCustomFieldList.add(invCustomField);
// Adding the Invoice Custom Fields
nsInvoice.put('customFieldList', new Map<String,Object>{'customField'=>invCustomFieldList});
// Initializing the Invoice 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', 3);
// 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', 'custcol_checkbox');
liCustomField.put('value', 'true');
liCustomFieldList.add(liCustomField);
// Adding the Invoice Line Item Custom Fields
lineItem.put('customFieldList', new Map<String, Object>{'customField'=>liCustomFieldList});
lineItemList.add(lineItem);
// Adding the Line Items to Invoice
Map<String, Object> invLineitemList = new Map<String, Object>();
invLineitemList.put('item', lineItemList);
nsInvoice.put('itemList', invLineitemList);
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('invoices', new List<Object>{nsInvoice});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'createInvoice');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);