We can create a sales order by calling the insert method after entering values into the sales table buffer. Instead of that, we can directly use a standard entity.
This process I have used in integrations. I get the data by 3rd application and I insert that data into the new table. For this table, I created a new entity and I gave that entity name to the customer. After I get the data I have written a batch job with the following code.
// Sales order header.
SalesOrderHeaderV2Entity headerEntity; Parameters parameters = Parameters::find(); CustTable custTable = CustTable::find(parameters.CustAccount);testTable TestTable testTable; ; ttsbegin; headerEntity.clear(); headerEntity.initValue(); headerEntity.InvoiceCustomerAccountNumber = parameters.CustAccount; headerEntity.OrderingCustomerAccountNumber = parameters.CustAccount; headerEntity.SalesOrderOriginCode = parameters.SalesOriginId; headerEntity.CustomersOrderReference = OrderCode; headerEntity.SalesOrderName = custTable.name(); headerEntity.DeliveryAddressDescription = custTable.name(); headerEntity.DeliveryAddressName = custTable.name(); headerEntity.DeliveryAddressDescription = custTable.name(); headerEntity.DeliveryAddressCountryRegionId = custTable.countryRegionId(); headerEntity.DeliveryAddressCity = TownCity; headerEntity.DeliveryAddressZipCode = PostCode; headerEntity.DeliveryAddressStreet = strFmt('%1 %2 %3 %4 %5 %6 %7 Phone: %8' , testTable.RecipientTitle,
testTable.RecipientFirstName,
testTable.RecipientLastName,
testTable.Address1, testTable.Address2,
testTable.Suburb, testTable.Region,
testTable.Phone);
headerEntity.DefaultShippingWarehouseId = parameters.DefaultWarehouseId;
headerEntity.DefaultShippingSiteId = InventLocation::find(
parameters.DefaultWarehouseId).inventSiteId;
headerEntity.DeliveryModeCode = parameters.DlvModeId;
headerEntity.InclTax = NoYes::Yes;
headerEntity.insert();
// Sales line.
SalesOrderLineV2Entity SalesOrderLineV2Entity;
InventDimCombination inventDimCombination;
CustVendExternalItem custVendExternalItem;
ExtCodeValueTable codeValueTable;
InventTable inventtable;
CustTable custTableLoc = custTable::find(_customerAccount);
Parameters Parameters = Parameters::find();
;
if (testTable.VariantDetails)
{
codeValueTable = ExtCodeValueTable::findValue(tableNum(InventDimCombination),
ExtCodeSubModule::None, Parameters.ExtCodeId,
testTable.SupplierSKU);
inventDimCombination = InventDimCombination::findRecId(codeValueTable.ExtCodeRelationRecId);
inventtable = InventTable::find(inventDimCombination.ItemId);
if (!inventDimCombination)
{
throw error("Product code not found");
}
}
else
{
custVendExternalItem = CustVendExternalItem::findExternalItemId(
ModuleInventPurchSalesVendCustGroup::Cust,
flyBuyparameters.CustAccount,
testTable.SupplierSKU);
if (!custVendExternalItem)
{
throw error("Product code not found");
}
inventtable = InventTable::find(custVendExternalItem.ItemId);
select inventDimCombination
where inventDimCombination.ItemId == inventtable.ItemId;
}
SalesOrderLineV2Entity = null;
SalesOrderLineV2Entity.SalesOrderNumber = _salesId;
SalesOrderLineV2Entity.ItemNumber = inventtable.ItemId;
SalesOrderLineV2Entity.OrderedSalesQuantity = testTable.Quantity;
SalesOrderLineV2Entity.SalesPrice = testTable.UnitCostPrice;
SalesOrderLineV2Entity.LineAmount = testTable.TotalCostPrice;
//defaulting inventDimId starts
SalesTable salesTableLoc = SalesTable::find(_salesId);
if (salesTableLoc.InventLocationId)
{
SalesOrderLineV2Entity.ShippingSiteId = salesTableLoc.InventSiteId;
SalesOrderLineV2Entity.ShippingWarehouseId = salesTableLoc.InventLocationId;
}
else
{
SalesOrderLineV2Entity.ShippingSiteId = custTableLoc.InventSiteId;
SalesOrderLineV2Entity.ShippingWarehouseId = custTableLoc.InventLocation;
}
if (inventDimCombination)
{
SalesOrderLineV2Entity.retailVariantId = inventDimCombination.RetailVariantId;
SalesOrderLineV2Entity.ProductColorId = inventDimCombination.inventDim().InventColorId;
SalesOrderLineV2Entity.ProductSizeId = inventDimCombination.inventDim().InventSizeId;
SalesOrderLineV2Entity.ProductStyleId = inventDimCombination.inventDim().InventStyleId;
}
if (SalesOrderLineV2Entity.validateWrite())
{
SalesOrderLineV2Entity.insert();
}
Keep daxing!!
No comments:
Post a Comment