Hi Guys,
Today I am going to explain you , how to copy a existing sales order header and lines and create a new Sales Order.
Step 1:
Add two new control in
Form level Design
1)
SelectFromExistingSalesId (ControlType-CheckBox)
2)ExistingSalesId(ControlType-StingEdit)
Step 2:
Write a single line of
code inside From Level init() method
ExistingSalesId.enabled(false);//Make
the ExistingSalesId control Disable when the form open
Step 3:
write
a piece of code inside SelectFromExistingSalesId
checkbox Control modified() method
public
boolean
modified()
{
boolean
ret;
ret
= super();
if(SelectFromExisitngSalesId.value()==1)
{
ExistingSalesId.enabled(true);
}
else
{
ExistingSalesId.enabled(false);
}
return
ret;
}
Step 4:
create a new method CreateSalesLines in the form level
public
void
createSalesLine(SalesId _salesId,ItemId _itemId)
{
SalesLine
salesLine;
salesLine.clear();
salesLine.SalesId
= _salesId;
salesLine.ItemId
= _itemId;
salesLine.createLine(NoYes::Yes,
//
Validate
NoYes::Yes,
//
initFromSalesTable
NoYes::Yes,
//
initFromInventTable
NoYes::Yes,
//
calcInventQty
NoYes::Yes,
//
searchMarkup
NoYes::Yes);
}
Step 5:
write
a piece of code inside ExistingSalesId
Control modified() method
public
boolean
modified()
{
SalesTable
salesTableBuff;
SalesLine
salesLineBuff;
ItemId
existItemId;
SalesId
currentSalesId;
SalesIdBase
existSalesId;
boolean
ret;
ret
= super();
existSalesId=ExistingSalesId.valueStr();//Gets
the Existing Sales Id
select
firstOnly
SalesId,CustAccount from
salesTableBuff
where
salesTableBuff.SalesId == existSalesId;
SalesTable.CustAccount
= salesTableBuff.CustAccount;
currentSalesId=
SalesTable.SalesId; //Gets the Newly generated Sales Id
SalesTable_ds.object(fieldNum(SalesTable,CustAccount)).modified();
SalesTable.insert();
while
select
ItemId from
salesLineBuff where
salesLineBuff.SalesId == existSalesId
{
existItemId=salesLineBuff.ItemId;
element.createSalesLine(currentSalesId,
existItemId);
}
return
ret;
}
Output:
A New Sales Oder is Created
That's it ........
Happy Daxing....