Dear All,
AS per customer requirement i added one button in Sales Order form "Import Lines".
When user clicked on button "Import Lines" then it will ask for browse file to import.
Then select file and OK.
It's properly inserted lines in to Sales Line.
Then user go to Document Status > Release. Once clicked then it will throw an error
******
NOTE :
If i closed the Sales Order form and again clicked on Document Status > Release. then it will Released .
It work absolutely fine.
I think it's refresh issue????
******
Here is my code :
Button > ImportLines
Clicked() :
void clicked()
{
Args args = new Args();
;
element.InsertSalesLine();
super();
}
void InsertsalesLine()
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
System.DateTime ShlefDate;
FilenameOpen filename;
DialogField dialogFilename;
Dialog dialog;
PriceDiscTable priceDiscTable;
int row;
int i;
str salesId;
PriceDiscItemRelation itemId, item;
SalesOrderedQty qty;
str name;
SalesUnit UOM, fromUnit,toUnit;
str crateCheck;
HSNCode_IN hsnCode;
#Excel
// For real values
str COMVariant2Str(COMVariant _cv,
int _decimals = 0,
int _characters = 0,
int _separator1 = 0,
int _separator2 = 0)
{
switch(_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R4):
return num2str(_cv.float(),
_characters,
_decimals,
_separator1,
_separator2);
case (COMVariantType::VT_R8):
return num2str(_cv.double(),
_characters,
_decimals,
_separator1,
_separator2);
case (COMVariantType::VT_DECIMAL):
return num2str(_cv.decimal(),
_characters,
_decimals,
_separator1,
_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),
123,
2,
1,
2,
1,
4);
case (COMVariantType::VT_EMPTY):
return "";
default:
throw error(strfmt("@SYS26908",
_cv.variantType()));
}
return "";
}
// end
;
dialog = new Dialog("Sales line Upload");
dialogFilename = dialog.addField(typeId(FilenameOpen));
dialog.filenameLookupFilter(["@SYS28576",#XLSX,"@SYS28576",#XLS]);
dialog.filenameLookupTitle("Upload from Excel");
dialog.caption("Sales line Upload");
dialogFilename.value(filename);
if(!dialog.run())
return;
filename = dialogFilename.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
row = 1;
try
{
do
{
ttsbegin;
row++;
itemId = cells.item(row, 1).value().bStr();
name = cells.item(row, 2).value().bStr();
qty = str2num(ComVariant2str(cells.item(row,3).value()));
UOM = cells.item(row, 4).value().bStr();
crateCheck = cells.item(row, 5).value().bStr();
salesId = salesTable.SalesId;
salesTable = SalesTable::find(salesId);
salesLine.clear();
salesLine.initValue();
salesLine.initFromSalesTable(salesTable);
// Validate Item ID
salesLine.ItemId = itemId;
salesLine.validateField(fieldnum(salesLine, ItemId));
salesLine.modifiedField(fieldnum(salesLine, ItemId));
// Validate HSN code
hsnCode = inventTable::find(itemId).HSNCode_IN;
If(!hsnCode)
{
info(strfmt("HSN code is not present for Item ID : %1",ItemId));
}
// check HSN code is NOT BLANK ****
if(itemId && hsnCode != "")
{
// Validate Quantity
salesLine.SalesQty = qty;
salesLine.validateField(fieldnum(salesLine, SalesQty));
salesLine.modifiedField(fieldnum(salesLine, SalesQty));
// BypassCrate
if(crateCheck == "Yes")
{
salesLine.ByPassCrateCheck = noyes::Yes;
}
else
{
salesLine.ByPassCrateCheck = noyes::No;
}
// Validate Sales unit
salesLine.SalesUnit = UOM;
salesLine.validateField(fieldnum(salesLine, SalesUnit));
salesLine.modifiedField(fieldnum(salesLine, SalesUnit));
// Create Lines ****
salesLine.createLine(NoYes::Yes,// Validate
NoYes::Yes, // initFromSalesTable
NoYes::Yes, // initFromInventTable
NoYes::Yes, // calcInventQty
NoYes::Yes, // searchMarkup
NoYes::No); // searchPrice
// Update forcefully excel Unit in to Sales Unit
salesLine.SalesUnit = UOM;
// salesPrice
while select ItemRelation,ItemCode,AccountRelation,ToDate,Amount from priceDiscTable
where priceDiscTable.ItemRelation == itemId
&& priceDiscTable.ItemCode == TableGroupAll::Table
&& priceDiscTable.AccountRelation == salesTable.PriceGroupId
&& priceDiscTable.ToDate == global::dateNull()
{
if(priceDiscTable)
{
salesLine.SalesPrice = priceDiscTable.Amount;
}
}
// end
// Update Lines ****
salesLine.selectForUpdate(true);
salesLine.update();
i++;
ttscommit;
}// end if
type = cells.item(row+1, 1).value().variantType();
}
while(type != COMVariantType::VT_EMPTY);
application.quit();
info(strfmt("%1",int2str(i)+' '+'Records are inserted sussessfully'));
}
catch
{
Error("Upload Failed");
}
SalesLine_ds.refresh();
SalesLine_ds.research();
// end
}
Can you please let me know how to reslove this issue.
Please give me more shed on this.
Thanks!
Arpan
*This post is locked for comments