ax 2012

how to create sales order by code with more then one lines ax 2012. might help you.

We have some processes in ax which creates sales orders. One example could be creating a sales order from sales quotation when the quotation has been confirmed. You can take that logic as reference.




Hi Kranthi,

i write a job and i use “salesLine.createLine(true, true, true, true, true, true);” in my code…
when i am try to insert more then one line this code is not working…

plz help me…

why do you mean by that? Please explain.

i have to insert dimension by code in sales order…

can you show me your code?

static void Job3(Args _args)


SysExcelApplication application;

SysExcelWorkbooks workbooks;

SysExcelWorkbook workbook;

SysExcelWorksheets worksheets;

SysExcelWorksheet worksheet;

SysExcelCells cells;

COMVariantType type;

FileName filename;

SalesFormLetter formLetterObj;

NumberSeq numberSeq;

SalesTable salesTable;

SalesLine salesLine;

InventDim InventDim;

int row;

str _ItemId;

real _qty;

str _unit;

str _siteid


application = SysExcelApplication::construct();

workbooks = application.workbooks();

filename = “D:\New folder\Final.xlsx”;




catch (Exception::Error)


throw error(“File cannot be opened.”);


workbook = workbooks.item(1);

worksheets = workbook.worksheets();

worksheet = worksheets.itemFromNum(1); //Here 3 is the worksheet Number

cells = worksheet.cells();

numberSeq = NumberSeq::newGetNum(SalesParameters::numRefSalesId());


salesTable.SalesId = numberSeq.num();


salesTable.CustAccount = ‘1101’;


if (!salesTable.validateWrite())


throw Exception::Error;







_ItemId = cells.item(row,1).value().bStr();

_qty = any2int(cells.item(row, 2).value().toString());

_unit = cells.item(row, 3).value().bStr();

_siteid = cells.item(row, 2).value().bStr();

salesLine.SalesId = salesTable.SalesId;

salesLine.ItemId = _ItemId;

salesline.SalesQty = _qty;

salesline.SalesUnit = _unit;

InventDim.InventSiteId =_siteid;

salesLine.createLine(NoYes::Yes, NoYes::Yes, NoYes::Yes, NoYes::Yes, NoYes::No);


type = cells.item(row+1, 1).value().variantType();


while (type != COMVariantType::VT_EMPTY);


formLetterObj = SalesFormLetter::construct(DocumentStatus::Invoice);


info(strFmt(“Sales order ‘%1’ has been created”, salesTable.SalesId));


you have not used the inventDim buffer to get an inventDimId.

salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;

not working??

I did solve this issue already but i forget how to solved this. i took help from you can take help this resource, it could be helpful for you. hope your problem might be solved. [:)]

Hello kranthi

can u please give me the solution of this Problem.

What ever the dimensions you are setting are being overridden in createLine method

salesLine.createLine(NoYes::Yes, NoYes::Yes, NoYes::Yes, NoYes::Yes, NoYes::No);

The third parameter, is responsible to init the default dimensions from item. Try by setting it false.

Try to debug and see if you have any other issues.