Hi all,
I need your help creating Print Management Settings dynamically with x++ (2012 R2). If you are not familiar with this feature have a look here http://dynamicsaxtipoftheday.com/2013/10/30/use-print-management-to-automatically-email-documents-to-customers-vendors/
The settings are stored in two tables:
PrintMgmtSettings
PrintMgmtDocInstance
the settings itself are stored in the class "PrintMgmtSetupSettingsDefault" which is packed in the container field PrintMgmtSettings.PrintJobSettings
My challenge currently is that I can't create an instance of this class!
My goal eventually is, to create a DIEF entity to import Print Management Settings for Customer and Vendor Master Data... any help Creating Print Management Settings via x++ greatly appreciated!!
*This post is locked for comments
Please refer to link below to create print management settings in X++
Hi,
Please refer the following link:
(x++ job to export customer print management)
community.dynamics.com/.../x-job-to-export-customer-print-management
Thanks for Sharing this Torkia,
Is there any way we could do the other way around? I mean, to export the information stored in the Print Management setup to Excel / txt file?
Regards,
Juliano Martins
This thread helped me to resolve an issue. thank you all for sharing your code and View.
Thanks Torkia !
This works perfectly.. I did notice that the file is delimeted with | (pipe) and not CSV, so I just changed the code to look for a comma :)
.....
.....
filetype type;
container record;
str Delimiter = ",";
int totalRecords;
int PriorityIDInt;
....
....
I'm not able to attach my csv file. Below an example of the content. Let me know if you need more help.
PrintType|AccountNum|NodeType|DocumentType|DocumentTypeID|Name|EmailTo|EmailSubject|EmailAttachmentFileFormat|Supress|PriorityID|ReportFormat|NumberOfCopies|PrintMediumType
Copy|10003|CustTable|SalesOrderInvoice|1| SO Invoice Email||Invoice / Facture|PDF|No|1|SalesInvoice.Report|2|Email
Copy|10004|CustTable|SalesOrderInvoice|1| SO Invoice Email||Invoice / Facture|PDF|No|1|SalesInvoice.Report|2|Email
Copy|10005|CustTable|SalesOrderInvoice|1| SO Invoice Email||Invoice / Facture|PDF|No|1|SalesInvoice.Report|1|Email
Copy|10006|CustTable|SalesFreeTextInvoice|5| Free Text Invoice Email||Invoice / Facture|PDF|No|1|FreeTextInvoice.Report|2|Email
Copy|10013|CustTable|SalesFreeTextInvoice|5| Free Text Invoice Email||Invoice / Facture|PDF|No|1|FreeTextInvoice.Report|2|Email
Copy|10015|CustTable|SalesFreeTextInvoice|5| Free Text Invoice Email||Invoice / Facture|PDF|No|1|FreeTextInvoice.Report|1|Email
Copy|10020|CustTable|SalesOrderConfirmation|2| SO Confirmation Email1||SO Confirmation|PDF|No|1|SalesConfirm.Report|1|Email
Copy|10020|CustTable|SalesOrderConfirmation|2| SO Confirmation Email2||SO Confirmation|PDF|No|2|SalesConfirm.Report|1|Email
Copy|10030|CustTable|SalesOrderConfirmation|2| SO Confirmation Email1||SO Confirmation|PDF|No|1|SalesConfirm.Report|1|Email
Copy|10030|CustTable|SalesOrderConfirmation|2| SO Confirmation Email2||SO Confirmation|PDF|No|2|SalesConfirm.Report|1|Email
Thanks VERY much Torkia!
Can I ask you to possibly send me an example CSV import file? I'm not too sure what some of the 14 fields are referencing.
Thanks again
James
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));
}
Hi Kim
I'm new to AX - can you guide me on how to carry out the above instructions?
Thanks
James
Would it be possible to add for example the Terms and Conditions in here to be automatically attached along the Report?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,134 Super User 2024 Season 2
Martin Dráb 229,928 Most Valuable Professional
nmaenpaa 101,156