Below is a sample code on how to bill a Sales Order via Web Services in C# (.NET). Make sure that you change internalId with the value of the Sales Order you wish to bill.
Sample code snippet in C#:
private void billSalesOrder() {
private Preferences _prefs;
private NetSuiteService _service;
_prefs.ignoreReadOnlyFields = true;
_prefs.ignoreReadOnlyFieldsSpecified = true;
InitializeRef initRef = new InitializeRef();
initRef.type = InitializeRefType.salesOrder;
initRef.typeSpecified = true;
initRef.internalId = "593";
InitializeRecord initRecord = new InitializeRecord();
initRecord.type = InitializeType.cashSale;
initRecord.reference = initRef;
ReadResponse readResponse = _service.initialize(initRecord);
Console.WriteLine("ReadResponse has been executed...");
if (readResponse.status.isSuccess) {
CashSale cashSale = new CashSale();
cashSale = (CashSale)readResponse.record;
cashSale.createdFrom.internalId = initRef.internalId;
cashSale.createdFrom.name = "Sales Order #" + initRef.internalId;
cashSale.promoCode = null;
WriteResponse writeResponse = _service.add(cashSale);
Console.WriteLine("WriteResponse has been executed...");
if (writeResponse.status.isSuccess) {
Console.WriteLine("Sales Order has been converted to Cash Sale");
} else {
Console.WriteLine("Last process failed.");
foreach (StatusDetail statusDetail in writeResponse.status.statusDetail) {
Console.WriteLine("\n\nType: " + statusDetail.type + "\n" +
"Code: " + statusDetail.code + "\n" +
"Message: " + statusDetail.message + "\n\n");
}
}
} else {
Console.WriteLine("ReadResponse failed...");
foreach (StatusDetail statusDetail in readResponse.status.statusDetail)
{
Console.WriteLine("\n\nType: " + statusDetail.type + "\n" +
"Code: " + statusDetail.code + "\n" +
"Message: " + statusDetail.message + "\n\n");
}
}
Console.WriteLine("\n\n\n\n");
}
private Preferences _prefs;
private NetSuiteService _service;
_prefs.ignoreReadOnlyFields = true;
_prefs.ignoreReadOnlyFieldsSpecified = true;
InitializeRef initRef = new InitializeRef();
initRef.type = InitializeRefType.salesOrder;
initRef.typeSpecified = true;
initRef.internalId = "593";
InitializeRecord initRecord = new InitializeRecord();
initRecord.type = InitializeType.cashSale;
initRecord.reference = initRef;
ReadResponse readResponse = _service.initialize(initRecord);
Console.WriteLine("ReadResponse has been executed...");
if (readResponse.status.isSuccess) {
CashSale cashSale = new CashSale();
cashSale = (CashSale)readResponse.record;
cashSale.createdFrom.internalId = initRef.internalId;
cashSale.createdFrom.name = "Sales Order #" + initRef.internalId;
cashSale.promoCode = null;
WriteResponse writeResponse = _service.add(cashSale);
Console.WriteLine("WriteResponse has been executed...");
if (writeResponse.status.isSuccess) {
Console.WriteLine("Sales Order has been converted to Cash Sale");
} else {
Console.WriteLine("Last process failed.");
foreach (StatusDetail statusDetail in writeResponse.status.statusDetail) {
Console.WriteLine("\n\nType: " + statusDetail.type + "\n" +
"Code: " + statusDetail.code + "\n" +
"Message: " + statusDetail.message + "\n\n");
}
}
} else {
Console.WriteLine("ReadResponse failed...");
foreach (StatusDetail statusDetail in readResponse.status.statusDetail)
{
Console.WriteLine("\n\nType: " + statusDetail.type + "\n" +
"Code: " + statusDetail.code + "\n" +
"Message: " + statusDetail.message + "\n\n");
}
}
Console.WriteLine("\n\n\n\n");
}
No comments:
Post a Comment