create sales order

26 Jul

void CreateSalesOrder(container con,CustAccount custAccount,Description custDescription)
NumberSeq num;
str customerRef;
str deliveryName;
str deliveryStreet;
ExternalItemId externalItemId;


//create sales table

num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
newSalesId = num.num();

if (salesTable::exist(newSalesId))
checkFailed(strfmt(“@LIQ1978”, newSalesId));
throw error(“@SYS23020”);

salesTable.SalesId = newSalesId;

if(custDescription != “”)
salesTable.SalesName = custDescription;

//fetch the customer details from cust table using account no selected from drop-down list
select * from custTable where custTable.AccountNum == custAccount;

salesTable.CustAccount = custTable.AccountNum;
salesTable.InvoiceAccount = custTable.InvoiceAccount;
salesTable.SalesType = SalesType::Sales;
salesTable.SalesStatus = SalesStatus::Backorder;
salesTable.CurrencyCode = custTable.Currency;

salesTable.CustGroup = custTable.CustGroup;
salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::SalesLeadTime;

//Set dates as systemDateTime
salesTable.ReceiptDateRequested = systemdateget();
salesTable.ShippingDateRequested = systemdateget();

salesTable.PurchOrderFormNum = conpeek(con,4);
customerRef = substr(conpeek(con,7),7,2);
salesTable.CustomerRef = customerRef;
salesTable.LanguageId = #Language;
salesTable.DlvMode = #DlvMode;

//Init from cust table

//Overwrite customer address with the address from user file.
//concatenate string
deliveryName = conpeek(con,8) + ‘ ‘ + conpeek(con,9) + ‘ ‘ + conpeek(con,10);
salesTable.DeliveryName = deliveryName;
//concatenate string
deliveryStreet = conpeek(con,11) + ‘ \ ‘ + conpeek(con,12) + ‘ ‘ + conpeek(con,13);
salesTable.DeliveryStreet = deliveryStreet;

salesTable.DeliveryCity = strrtrim(conpeek(con,14));
salesTable.DeliveryState = strrtrim(conpeek(con,15));
salesTable.DeliveryZipCode = strrtrim(conpeek(con,16));
salesTable.ShipCarrierDeliveryContact = conpeek(con,17);

//Craete Sales Order

// Create Sales Order Line
salesLine.SalesId = salesTable.SalesId;

externalItemId = conpeek(con,3);
//Get ItemId from custVendExternalItem table using externalItemId from file
select ItemId,RecId from custVendExternalItem where custVendExternalItem.ExternalItemId == externalItemId;
if(custVendExternalItem.RecId == 0)
throw error(‘@LIQ2648’);
//Set sales item id from custVendExternalItem table
salesLine.ItemId = custVendExternalItem.ItemId;
salesLine.SalesUnit = InventTable::find(salesLine.ItemId).salesUnitId();
select * from inventTable where inventTable.ItemId == salesLine.ItemId;

select * from inventDim where inventDim.InventLocationId == custTable.InventLocation && inventDim.InventSiteId == custTable.InventSiteId;

if(inventDim.RecId != 0)
salesLine.InventDimId = inventDim.inventDimId;
throw error(“@LIQ1979”);

//Set Qty as 1 by default as per business – Bo
salesLine.SalesQty = 1;
salesLine.ConfirmedDlv = salesTable.ShippingDateConfirmed;
salesLine.lineNum = SalesLine::lastLineNum(salesLine.salesId) + 1.0;
salesLine.LinePercent = 10;
salesLine.RemainInventPhysical = 1;
salesLine.RemainSalesPhysical = 1;
salesLine.DlvMode = #DlvMode;
salesLine.SalesStatus = SalesStatus::Backorder;

//Insert sales line items


Leave a comment

Posted by on July 26, 2011 in X++



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


AxaptaHut ax = new AxaptaHut();

All About Dynamics 365

Dynamics 365, D365, Implementor

Syed Rafay Ali

This blog contains information about Functional techniques and guidelines in Microsoft Dynamics AX, including tips, tricks, tutorials, tools and upcoming news enhancement in Microsoft Dynamics Ax

Philippsen's Blog

Everyday findings in my world of .net and related stuff

Microsoft Dynamics AX

A great site


All things Blockchain, ERP and IoT

Dynamics Ax

Technical Knowledge


A blog about implementing Microsoft Dynamics AX and Dynamics 365 for Operations

Microsoft Dynamics 365 Blog

Start your organization's digital transformation with Dynamics 365, A Blog by Sandeep Chaudhury

DEVSerra - Dynamics AX development blog

Your official Microsoft Dynamics AX blog.


Discovering Dynamics


A blog by Hai Nguyen

Learn Dynamics Ax with Johnkrish

Live as if you were to die tomorrow. Learn as if you were to live forever - Mahatma Gandhi ****** The more I learn, the less I know - Albert Einstein

Twisted Untwirled

Just another site


Just another site

guyterry's Dynamics AX blog

Just another Dynamics AX blog

%d bloggers like this: