Hi,
I have a requirement. I want to show all the sales order lines against any particular sales order that is specified. For example, If a Sales Order has 2 lines, I would like to info the contents of these two lines in the same window.
I have created a job. In the job, I have taken tables of SalesTable and SalesLine. I have selected SalesTable with while loop and selected a particular Sales Order with field SalesId. In the {} braces, I have tried to show some fields from the SalesLine table.
It returns just first line’s value and not all the lines. How can I achieve this. Please help.
Could you show us your code, please? (Use Insert > Insert Code to paste it here.)
static void getSalesLines(Args _args)
{
SalesTable salesTable;
SalesLine salesLine;
while select salesTable
where salesLine.SalesId == salesTable.SalesId
&& salesTable.SalesId == '000735'
{
info(strFmt("%1, %2", salesLine.SalesQty, salesLine.itemName()));
}
}
static void getSalesOrderLine(Args _args)
{
SalesTable salesTable;
SalesLine salesLine;
while select salesTable
where salesTable.SalesId == '000010'
join salesLine
where salesLine.SalesId == salesTable.SalesId
{
info(strFmt("%1, %2, %3", salesLine.ItemId, salesLine.SalesQty, salesLine.SalesUnit));
}
}
corrected with the following code. Now the Lines are appearing. Is it best way of doing ??? Thanks by the way for your response.
There are a few things you can improve.
You aren’t using SalesTable for anything, therefore you can get rid of it:
SalesLine salesLine;
while select salesLine
where salesLine.SalesId == '000010'
{
info(strFmt("%1, %2, %3", salesLine.ItemId, salesLine.SalesQty, salesLine.SalesUnit));
}
Also, you can improve peformance by using a field list. You’re now loading all fields from database, although you need just three of them and you ignore the rest. Let’s select just those three fields:
SalesLine salesLine;
while select ItemId, SalesQty, SalesUnit from salesLine
where salesLine.SalesId == '000010'
{
info(strFmt("%1, %2, %3", salesLine.ItemId, salesLine.SalesQty, salesLine.SalesUnit));
}