web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Help Creating Print Management Settings via x++

(1) ShareShare
ReportReport
Posted on by 4

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

I have the same question (0)
  • santhosh kumar 1212 Profile Picture
    215 on at
    RE: Help Creating Print Management Settings via x++

    Hi Kim,

    Please let me know if you solved creating print mgmt. settings dynamically using x++ script.

    Thanks

  • Suggested answer
    Kim Kopowski Profile Picture
    4 on at
    RE: Help Creating Print Management Settings via x++

    yeah... just use a new instance of SRSPrintDestinationSettings to serialize an empty container. See example below... use "printDestinationSetting" to pack/unpack container "printerSetting"

    all you need to do now, is to fill in the actual values for the settings (EG: Document Type "Sales Order Confirmation", NodeType "Customer", NodeTypeReference "US-027"). 

    // Target Buffers
    PrintMgmtDocInstance printMgmtDocInstance;
    PrintMgmtSettings printMgmtSettings;
    PrintMgmtReportFormat printMgmtreportFormat;

    // other
    container printerSetting = conNull();
    SRSPrintDestinationSettings printDestinationSetting = new SRSPrintDestinationSettings();

    // Populate/Create TargetBuffer(s)
    printMgmtDocInstance.DocumentType = printMgmtReportFormat_DocumentType;
    printMgmtDocInstance.Name = printMgmtDocInstance_Name;
    printMgmtDocInstance.NodeType = printMgmtDocInstance_NodeType;
    printMgmtDocInstance.PrintType = printType;
    printMgmtDocInstance.PriorityId = 1;
    printMgmtDocInstance.ReferencedRecId = refRecId;
    printMgmtDocInstance.ReferencedTableId = refTableId;
    printMgmtDocInstance.insert();

    // just use a new instance of SRSPrintDestinationSettings to serialize an empty container
    printDestinationSetting.unpack(printerSetting);
    printDestinationSetting.printMediumType(srsPrintMediumType);
    printDestinationSetting.emailTo(toEmailString);
    printDestinationSetting.emailCc(ccEmailString);
    printDestinationSetting.printerName(printerName);
    printerSetting = printDestinationSetting.pack();


    printMgmtSettings.clear();
    printMgmtSettings.Description = printmgmtdocInstance.Name;
    printMgmtSettings.NumberOfCopies = 1;
    printMgmtSettings.ParentId = printmgmtdocInstance.RecId;
    printMgmtSettings.PrintJobSettings = printerSetting;
    printMgmtSettings.PriorityId = printMgmtDocInstance.PriorityId;
    printMgmtSettings.ReportFormat = printmgmtreportFormat.RecId;
    printMgmtSettings.insert();

  • santhosh kumar 1212 Profile Picture
    215 on at
    RE: Help Creating Print Management Settings via x++

    Hi Kim,

    Thank you..!

  • Suggested answer
    adam260 Profile Picture
    1,871 on at
    RE: Help Creating Print Management Settings via x++

    One of the other ways to do this if you want more control over the actual email that gets sent is to generate a pdf and then you can use a generic email class to format and send the email. This will allow you to send out a nicely formatted email with logos and dynamic text if you want to get crazy with it.

    Saving a Report to PDF: axcalated.blogspot.com/.../save-sales-confirmation-report-to-pdf.html

    Sending a html formatted email: axcalated.blogspot.com/.../send-email-within-axx-via-net-objects.html

  • Community Member Profile Picture
    on at
    RE: Help Creating Print Management Settings via x++

    Would it be possible to add for example the Terms and Conditions in here to be automatically attached along the Report?

  • SU-22040800-0 Profile Picture
    2,459 on at
    RE: Help Creating Print Management Settings via x++

    Hi Kim

    I'm new to AX - can you guide me on how to carry out the above instructions?

    Thanks

    James

  • Community Member Profile Picture
    on at
    RE: Help Creating Print Management Settings via x++

    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));

    }

  • SU-22040800-0 Profile Picture
    2,459 on at
    RE: Help Creating Print Management Settings via x++

    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

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Help Creating Print Management Settings via x++

    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

  • Suggested answer
    SU-22040800-0 Profile Picture
    2,459 on at
    RE: Help Creating Print Management Settings via x++

    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;

    ....

    ....

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans