Hi James,
I'm working on importing print management. Here is a script that I have just coded and tested. Let me know if you need more help:
/// <summary>
/// Job for importing Print Management settings records from a CSV file.
/// </summary>
static void XX_DM_Import_PrintManagement2(Args _args)
{
Dialog dialog = new Dialog();
DialogField dialogField;
AsciiIo importFile;
str filePath,fileNameOnly;
filetype type;
container record;
str Delimiter = "|";
int totalRecords;
int PriorityIDInt;
str captain = "Select CSV file for Print Management";
int numberOfColumns = 14;
container printerSetting = conNull();
PrintMgmtSettings MgmtSettings;
PrintMgmtDocInstance instance;
SRSPrintDestinationSettings destination;
PrintMgmtReportFormat PrintMgmtReportFormat;
PrintMgmtDocumentType PrintMgmtDocumentType;
PrintMgmtDocInstanceType PrintMgmtDocInstanceType;
NoYes NoYes;
SRSReportFileFormat SRSReportFileFormat;
SRSPrintMediumType SRSPrintMediumType;
str PrintType, AccountNum, NodeType, DocumentType, DocumentTypeID, Name, EmailTo, EmailSubject, EmailAttachmentFileFormat, Supress, PriorityID, ReportFormat,NumberOfCopies, PrintMediumType;
CustTable CustTable;
VendTable VendTable;
dialogField=dialog.addField(extendedTypeStr(FilenameOpen),"Select File","Select file to import");
dialog.caption(captain);
dialog.filenameLookupFilter(['csv','*.csv']);
if(!dialog.run())
return;
[filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());
importFile = new AsciiIo(dialogField.value(), 'R');
if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning("Error in opening import file");
throw(Exception::Error);
}
importFile.inFieldDelimiter(Delimiter);
if((!importFile) || (importFile.status() != IO_Status::Ok))
{
warning("Error in opening log file");
throw(Exception::Error);
}
try
{
record = importFile.read();
while(importFile.status() == IO_Status::Ok)
{
record = importFile.read();
if(!record)
break;
else if(conLen(record) != 14)
continue;
totalRecords = totalRecords + 1;
PrintType = conPeek(record,1);
AccountNum = conPeek(record,2);
NodeType = conPeek(record,3);
DocumentType = conPeek(record,4);
DocumentTypeID = conPeek(record,5);
Name = conPeek(record,6);
EmailTo = conPeek(record,7);
EmailSubject = conPeek(record,8);
EmailAttachmentFileFormat = conPeek(record,9);
Supress = conPeek(record,10);
PriorityID = conPeek(record,11);
ReportFormat = conPeek(record,12);
NumberOfCopies = conPeek(record,13);
PrintMediumType = conPeek(record,14);
PriorityIDInt= str2int(PriorityID);
if (NodeType=='CustTable')
CustTable=CustTable::find(AccountNum);
else
{
if (NodeType=='VendTable')
VendTable=VendTable::find(AccountNum);
}
destination = new SRSPrintDestinationSettings(printerSetting);
destination.unpack(printerSetting);
destination.caption("@SYS131685");
destination.emailTo(EmailTo);
//destination.printMediumType(str2enum(SRSPrintMediumType,PrintMediumType));
destination.printMediumType(SRSPrintMediumType::Email);
destination.emailSubject(EmailSubject);
//destination.emailAttachmentFileFormat(str2enum(SRSReportFileFormat,EmailAttachmentFileFormat));
destination.emailAttachmentFileFormat(SRSReportFileFormat::PDF);
destination.numberOfCopies(1);
ttsBegin;
if (NodeType=='CustTable')
instance=PrintMgmtDocInstance::find(CustTable.RecId, CustTable.TableId, PrintMgmtNodeType::CustTable,str2int(DocumentTypeID) ,PriorityIDInt);
else
{
if (NodeType=='VendTable')
instance=PrintMgmtDocInstance::find(VendTable.RecId, VendTable.TableId, PrintMgmtNodeType::VendTable,str2int(DocumentTypeID) ,PriorityIDInt);
}
if (instance)
{
instance.selectForUpdate(true);
}
instance.Name = Name;
instance.DocumentType = str2int(DocumentTypeID);
instance.PrintType = str2enum(PrintMgmtDocInstanceType, PrintType);
instance.PriorityId = str2Int(PriorityID);
instance.Suppress = str2enum(NoYes,Supress);
if (NodeType=='CustTable')
{
instance.ReferencedTableId = CustTable.TableId;
instance.ReferencedRecId = CustTable.RecId;
instance.NodeType = PrintMgmtNodeType::CustTable;
}
else
if (NodeType=='VendTable')
{
instance.ReferencedTableId = VendTable.TableId;
instance.ReferencedRecId = VendTable.RecId;
instance.NodeType = PrintMgmtNodeType::VendTable;
}
if (instance)
instance.update();
else
instance.insert();
select firstOnly MgmtSettings order by PriorityID where MgmtSettings.ParentId==instance.RecId && MgmtSettings.PriorityID==PriorityIDInt;
if (MgmtSettings)
{
MgmtSettings.selectForUpdate(true);
}
MgmtSettings.ParentId = instance.RecId;
MgmtSettings.ReportFormat = PrintMgmtReportFormat::findByDescription(str2int(DocumentTypeID),ReportFormat).RecId;
MgmtSettings.PrintJobSettings = Destination.pack();
MgmtSettings.NumberOfCopies = str2int(NumberOfCopies);
MgmtSettings.PriorityId = str2Int(PriorityID);
if (MgmtSettings)
MgmtSettings.update();
else
MgmtSettings.insert();
ttsCommit;
if(instance && MgmtSettings)
{
info(strFmt("Data record for Line %9: %1, %2, %3, %4, %5, %6, %7, %8", conPeek(record,1), conPeek(record,2), conPeek(record,3), conPeek(record,4), conPeek(record,5), conPeek(record,6), conPeek(record,7), conPeek(record,8), totalRecords));
}
else
{
error(strFmt("Data record for Line %9: %1, %2, %3, %4, %5, %6, %7, %8", conPeek(record,1), conPeek(record,2), conPeek(record,3), conPeek(record,4), conPeek(record,5), conPeek(record,6), conPeek(record,7), conPeek(record,8), totalRecords));
}
}
}
catch(Exception::Error)
{
Throw(Exception::Error);
}
info(strFmt("Total Read Records = %1",totalRecords));
}