I need to create a duplicate line for each selection in another form.
In my closeOk method on the dialog form (the other form), I am able to change the field I want but the users want to be able to select all options they want and it to automatically create lines on the same quote with the different prices they chose.
I am trying to use the buf2Buf() where it takes the element.args().record() that I set to send over to the dialog form and copy the data of that line record into a new line record.
I have a loop: for however many selections it will fill in the quote line that was sent with element and then create additional ones that are duplicates of the element record. When I try to do this I get an error saying that the record already exists. That tells me that the recId is still the same but from what I read the buf2Buf method should ignore any system fields including recId.
public void closeOk()
{
int recordsCount;
super();
FormRun fr = element.args().caller() as FormRun;
FormDataSource fds = fr.dataSource(formDataSourceStr(SalesQuotationTable, SalesQuotationLine));
recordsCount = MJMPricingTmp_ds.recordsMarked().lastIndex(); //Total number of marked records
SalesQuotationLine quoteLineArgRecord = element.args().record();
MJMPricingTmp pricingTmp = MJMPricingTmp_ds.getFirst(1);
SalesQuotationLine quoteLine;
InventDim inventDim;
if(recordsCount == 1)
{
ttsbegin;
switch(quoteLineArgRecord.SalesUnit)
{
case "Mft":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalMft;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalMft;
break;
case "M":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalMtr;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalMtr;
break;
case "lb":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalLb;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalLb;
break;
case "kg":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalKg;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalKg;
break;
case "ea":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalEa;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalEa;
break;
default:
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalMft;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalMft;
break;
}
quoteLineArgRecord.write();
ttscommit;
}else
{
while(pricingTmp)
{
if(pricingTmp == MJMPricingTmp_ds.getFirst(1))
{
ttsbegin;
switch(quoteLineArgRecord.SalesUnit)
{
case "Mft":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalMft;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalMft;
break;
case "M":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalMtr;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalMtr;
break;
case "lb":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalLb;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalLb;
break;
case "kg":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalKg;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalKg;
break;
case "ea":
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalEa;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalEa;
break;
default:
quoteLineArgRecord.CsMpvListPrice = pricingTmp.TotalMft;
quoteLineArgRecord.SalesPrice = pricingTmp.TotalMft;
break;
}
quoteLineArgRecord.update();
ttscommit;
pricingTmp = MJMPricingTmp_ds.getNext();
}
else
{
SalesQuotationLine quoteLineOrig = quoteLineArgRecord;
ttsbegin;
buf2Buf(quoteLineOrig, quoteLine);
quoteLine.clear();
inventDim.clear();
quoteLine.itemIdChanged();
switch(quoteLine.SalesUnit)
{
case "Mft":
quoteLine.CsMpvListPrice = pricingTmp.TotalMft;
quoteLine.SalesPrice = pricingTmp.TotalMft;
break;
case "M":
quoteLine.CsMpvListPrice = pricingTmp.TotalMtr;
quoteLine.SalesPrice = pricingTmp.TotalMtr;
break;
case "lb":
quoteLine.CsMpvListPrice = pricingTmp.TotalLb;
quoteLine.SalesPrice = pricingTmp.TotalLb;
break;
case "kg":
quoteLine.CsMpvListPrice = pricingTmp.TotalKg;
quoteLine.SalesPrice = pricingTmp.TotalKg;
break;
case "ea":
quoteLine.CsMpvListPrice = pricingTmp.TotalEa;
quoteLine.SalesPrice = pricingTmp.TotalEa;
break;
default:
quoteLine.CsMpvListPrice = pricingTmp.TotalMft;
quoteLine.SalesPrice = pricingTmp.TotalMft;
break;
}
quoteLine.createLine();
ttscommit;
pricingTmp = MJMPricingTmp_ds.getNext();
}
}
}
}