If you would like to add a cash sale into NetSuite over web services, below is a sample on how to accomplish this. 
Please note you will need a valid login session for this code to work. 
Status stat = nss.login(p).status; 
if (stat.isSuccess) 
{ 
// internal id of customer 
RecordRef customer = new RecordRef(); 
customer.internalId = "4"; 
// internal id of a posting period 
RecordRef period = new RecordRef(); 
period.internalId = "4"; 
// internal id of a location 
RecordRef location = new RecordRef(); 
location.internalId = "2"; 
// internal id of an Item 
RecordRef item = new RecordRef(); 
item.internalId = "5"; 
// Creating the Cash Sale Item List object 
CashSaleItemList csil = new CashSaleItemList(); 
// Creating an array of CashSaleItem objects length of 1 
CashSaleItem[] csi = new CashSaleItem[1]; 
// Creating an object of type CashSale Item 
CashSaleItem csi1 = new CashSaleItem(); 
// Assigning the CashSaleItem object to the array of CashSaleItems 
csi[0] = csi1; 
// Assigning the Item record to the CashSaleItem Object. 
csi1.item = item; 
// Assigning the quantity of the item 
csi1.quantity = 5; 
// This is required when passing quantity. 
csi1.quantitySpecified = true; 
// Assigning the CashSaleItem array to the CashSaleItemList object. 
csil.item = csi; 
// Creating the CashSale Object. 
CashSale cs = new CashSale(); 
//Assigning the customer record to the CashSale object. 
cs.entity = customer; 
// Assigning transaction date to the CashSale Object 
cs.tranDate = System.DateTime.Now; 
// Assigning the Posting Period record to the CashSale Object. 
cs.postingPeriod = period; 
// Assigning the Location record to the CashSale Object 
cs.location = location; 
// Assigning the CashSaleItemList object to the CashSale Object. 
cs.itemList = csil; 
// Sending in the add request of a CashSale into NetSuite 
WriteResponse res = nss.add(cs); 
// Checking the status of the request. 
if (res.status.isSuccess) 
{ 
Console.WriteLine("Cash Sale Successfully Created"); 
Console.ReadKey(); 
} 
else 
{ 
Console.WriteLine("Cash Sale not successfully created" + res.status.statusDetail[0].message); 
Console.ReadKey(); 
}      
 
No comments:
Post a Comment