AX 2012 X++ Export cross company vendor emails
static void AllSupplierEmailExport(Args _args)
{
Dialog dialog = new Dialog();
DialogField dialogField;
AsciiIo exportFile;
str filePath, fileNameOnly;
filetype type;
str delimiter = ";";
int totalRecords;
VendTable vendTableAll;
VendTable vendTable;
container line;
dialogField = dialog.addField(extendedTypeStr(FilenameSave), "Select File", "Select file to export");
dialog.caption("Extracting Vendor Remit To details");
dialog.filenameLookupFilter(['csv','*.csv']);
setPrefix(dialog.caption());
if(!dialog.run())
{
warning("Dialog closed.");
return;
}
startLengthyOperation();
[filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());
exportFile = new AsciiIo(dialogField.value(), 'W');
if((!exportFile) || (exportFile.status() != IO_Status::Ok))
{
warning("Error in opening export file.");
throw(Exception::Error);
}
exportFile.outFieldDelimiter(delimiter);
try
{
while select crossCompany DataAreaId, count(RecId) from vendTableAll
group by DataAreaId
{
info(strFmt("%1 - %2 records", vendTableAll.dataAreaId, vendTableAll.RecId));
changeCompany(vendTableAll.dataAreaId)
{
vendTable = null;
while select vendTable
where vendTable.dataAreaId == vendTableAll.dataAreaId
{
line = conNull();
line += [vendTable.dataAreaId, vendTable.AccountNum, vendTable.name()];
line += DirParty::electronicAddressLocatorsByRole(vendTable.Party,
LogisticsElectronicAddressMethodType::Email,
enum2str(LogisticsLocationRoleType::RemitTo));
exportFile.write(line);
totalRecords++;
}
}
}
}
catch(Exception::Error)
{
warning("Error in writing export file.");
throw(Exception::Error);
}
exportFile.finalize();
info(strFmt("Total records exported = %1", totalRecords));
endLengthyOperation();
}
Comments
Post a Comment