import CSV with X++ for Dynamics 365 FO
/// <summary>
/// import color code
/// </summary>
class CFSImportColorCode
{
/// <summary>
/// main
/// </summary>
/// <param name = “_args”>_args</param>
public static void main(Args _args)
{
AsciiStreamIo file;
Array fileLines;
FileUploadTemporaryStorageResult fileUpload;
CFSEcoResColorCode colorCode;
CFSImportColorCode importColorCode = new CFSImportColorCode();
Counter counter = 0;
EcoResColorName color;
#OCCRetryCount
try
{
//Upload a file
fileUpload = File::GetFileFromUser() as FileUploadTemporaryStorageResult;
file = AsciiStreamIo::constructForRead(fileUpload.openResult());
if (file)
{
if (file.status())
{
throw error(“@SYS52680”);
}
file.inFieldDelimiter(‘;’); //separator
file.inRecordDelimiter(‘\r\n’);
}
//Read a CSV File
container rec;
ttsbegin;
while (!file.status())
{
counter++;
rec = file.read();
if (conLen(rec))
{
color = conPeek(rec, 2);
colorCode = CFSEcoResColorCode::find(color);
if(!colorCode.RecId)
{
colorCode.clear();
colorCode.Name = color;
colorCode.Code = conPeek(rec, 1);
colorCode.insert();
}
}
}
ttscommit;
info(“Operation complete.”);
}
catch (Exception::Deadlock)
{
retry;
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
}
posted on 2023-05-11 18:45 lingdanglfw 阅读(15) 评论(0) 编辑 收藏 举报