Create
1 min
To create a Vendor in NetSuite, use action as "createVendor" and pass the Vendor data in the requestJSON under "vendors".
Note: You can only create one record at a time
The following is an example of creating a Vendor where we are setting every possible field (See Vendor for the available fields). The response will return the response back from NetSuite, which includes the new NetSuite Vendor Id (internalId), plus the newly created Salesforce Vendor Id (salesforceID)
// Create a Map to store all the data of a Vendor
Map<String, Object> nsVendor = new Map<String, Object>();
nsVendor.put('companyName', 'Pyramid Construction Inc.');
nsVendor.put('currencyRecord', new Map<String, Object>{'internalId'=>'1'});
nsVendor.put('payablesAccount', new Map<String, Object>{'internalId'=>'114'});
nsVendor.put('subsidiary', new Map<String, Object>{'internalId'=>'1'});
nsVendor.put('terms', new Map<String, Object>{'internalId'=>'6'});
nsVendor.put('url', 'https://www.pyramid.com');
// Initializing the Vendor Custom Fields
List<Object> vendCustomFieldList = new List<Object>();
Map<String, Object> vendCustomField1 = new Map<String, Object>();
vendCustomField1.put('fieldType', 'select');
vendCustomField1.put('scriptId', 'custentity_atlas_pbcs_category');
vendCustomField1.put('valueLookup', new Map<String, Object>{'internalId'=>'1'});
vendCustomFieldList.add(vendCustomField1);
Map<String, Object> vendCustomField2 = new Map<String, Object>();
vendCustomField2.put('fieldType', 'date');
vendCustomField2.put('scriptId', 'custentity_renewal_date');
vendCustomField2.put('value', String.valueOf(DateTime.newInstance(2020, 12, 31).getTime()/1000));
vendCustomFieldList.add(vendCustomField2);
// Adding the Vendor Custom Fields
nsVendor.put('customFieldList', new Map<String, Object>{'customField'=>vendCustomFieldList});
// Initializing the Vendor Addresses
List<Object> addressBookList = new List<Object>();
Map<String, Object> addressBook = new Map<String, Object>();
Map<String, Object> addressbookAddress = new Map<String, Object>();
addressbookAddress.put('addr1', '2334 N. Michigan Avenue, Suite 1500');
addressbookAddress.put('city', 'Chicago');
addressbookAddress.put('state', 'IL');
addressbookAddress.put('country', '_unitedStates');
addressbookAddress.put('zip', '60601');
addressBook.put('addressbookAddress', addressbookAddress);
addressBook.put('defaultBilling', true);
addressBook.put('defaultShipping', true);
addressBook.put('isResidential', true);
addressBookList.add(addressBook);
nsVendor.put('addressbookList', new Map<String, Object>{'addressbook'=>addressBookList});
// Initializing the RequestJSON Data to be passed.
Map<String, Object> requestJSONMap = new Map<String, Object>();
requestJSONMap.put('vendors', new List<Object>{nsVendor});
String reqJSON = JSON.serialize(requestJSONMap);
Map<String, Object> reqObj = new Map<String, Object>();
reqObj.put('version', '1.0');
reqObj.put('action', 'createVendor');
reqObj.put('requestJSON', reqJSON);
// Placing a request to Breadwinner Global API
Map<String, Object> resp = breadwinner_ns.BreadwinnerNetSuiteAPI.call(reqObj);
System.debug(resp);