Posts

Generate and attach a SSRS report as PDF file in document attachment form through X++ code

                   Sometimes we face this requirement to attach a SSRS reports directly on attachment form. Following is the code that helps you to achieve.         str                              fileName;         String10                          Extension;         Args                              _args;         SRSPrintDestinationSettings   printerSettings;         System. Byte []                 reportBytes = new System. Byte [ 0 ]();         SRSProxy                      srsProxy;         SRSReportRunService              srsReportRunService = new SrsReportRunService ();                  Microsoft.Dynamics.AX.Framework.Reporting.Shared.ReportingService. ParameterValue []   parameterValueArray;         Map                           reportParametersMap;          str                           reportnamerun;         SRSReportExecutionInfo        executionInfo = new SRSReportExecutionInfo ();         System.IO. Stream               stream = null ;         _args = new Args ();     

Create an excel file and send it through Email in D365 using X++ code

Image
             This post is about creating an excel file using X++ and attach it as an Email(office 365 SMTP) attachment without saving it in local file location.  SysMailerMessageBuilder          mailer  = new SysMailerMessageBuilder (); SysMailerSMTP                    smtp    = new SysMailerSMTP (); RowNumber                        row     = 1 ; RESPDCLogTable                   pDCLogTable1; System.IO. MemoryStream  memoryStream     = new  System.IO. MemoryStream (); mailer.setSubject(strFmt( "PDC posted batch status %1" ,sessionDate)); mailer.setFrom( SysUserInfo ::find().Email); mailer.setBody( 'Please find the PDC Status report.' ); mailer.addTo(' ToMailAddress ' );     using ( var package = new OfficeOpenXml. ExcelPackage (memoryStream))   {       var worksheets = package.get_Workbook().get_Worksheets();       var worksheet  = worksheets.Add( "PDC batch status" );       var cells      = worksheet.get_Cells();       var cell       = cel

Convert string into ENUM str2enum in x++

Image
This post will explain how you can assign and convert string input either read from excel etc into ENUM type variable. For this example, we will be going to use PurchReqCreationStatus ENUM.  The ENUM has 2 key properties 1.       Name – ENUM element name 2.       Label – it is used as a string for ENUM conversion            PurchReqCreationStatus PurchReqCreationStatus;           str PurchReqCreationStatusValue = 'Approved' ;           PurchReqCreationStatus = str2Enum(PurchReqCreationStatus,PurchReqCreationStatusValue);          Info(enum2Str(PurchReqCreationStatus));          Info(enum2Str( PurchReqCreationStatus ::Approved));

How to get calling menu name in extensions D365

We can write logic based on a current form called from which menu item. Following is the code that helps you to achieve  get the calling menu name.     ///     /// </summary>     /// <param name="args"></param>     [ PostHandlerFor ( formStr ( CaseItemCreditLines ), formMethodStr ( CaseItemCreditLines , init))]     public static void  CaseItemCreditLines_Post_init( XppPrePostArgs args)     {         SalesLine   salesLine;         FormRun     fromRun    =  args.getThis();         if (fromRun.args().dataset() == tableNum ( SalesLine )   && fromRun.args().menuItemName() == menuItemDisplayStr ( CaseItemCreditLines ))         {             salesLine = fromRun.args().record();             fromRun.design( 0 ).controlName( formControlStr ( CaseItemCreditLines , sendMail)).visible( salesTable ::isRelatedPO_IsVOR( salesTable ::find(salesLine.SalesId)));         }       }

Open URL in browser using X++

In this blog article, we will see how we can open a URL in a web browser using X++ code. It is achieved using Browser the class which extends System Class Browser having the only method navigate(). It has three parameters from which only first is mandatory: 1.        downloadURL (string) – URL you want to browse. 2.        openInNewTab (Boolean) – It is used to specify URL should be open in the same tab or new tab 3.        showExitWarning (Boolean) – Prompt a dialog to exit the current page. class OpenURL {    public static void main( Args _args)    {         Browser browser = new Browser ();         browser.navigate( SystemParameters ::find().DALPowerBILink, true , false );         //OR         browser.navigate( "https://jonesd365.blogspot.com/" , true , false );     } } So, this will open URL within a new tab in the browser using X++.  

Open form via its AOT name in D365 Finance & operations

Image
  For developers, it can come handy if they can directly open the form via its AOT name in D365 finance & operations rather than opening via its menu item. To do so, you can simply search in the search bar by typing   form:<form AOT name> For example, users management form AOT name is PurchTable . When it is searched, all its references in ERP will be provided as search suggestion.

How to do string left or right padding in X++

This article will explain how you can do string padding with zeros or space with the specified length either left padded or right padded in X++. Often we have a requirement that the desired string should be of specific length (say 10) and if it is not of that length, it should be prefixed with 0. A practical example would be that we need to export bank or vendor txt file with the specific configuration at desired places for a string with a specific length from ERP. To do left padding,  strRFix   function can be used and to do right padding,  strLFix   function can used Syntax str strRFix(str _str,int _length,char _char= ‘ ‘) str strLFix(str _str,int _length,char _char= ‘ ‘) str value = 'Demo' ; //strRFix Info(strRFix(value, 7 , '0' )); // this will info '000Demo' Info(strRFix(value, 7 )); // this will info '   Demo' // 3 parameter is optional with default value of space   //strLFix Info(strLFix(value, 7 , '0' )); //this will info