Posts

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 

Conversion of amounts from one currency to another currency in D365

This article describes how can we convert amounts from one currency to another. ExchangeRateHelper ::curPrice2CurPrice(Price, FromCurrencyCode, ToCurrencyCode, ExchangeRateDate);

Create movement journal through X++ code in D365FO(Import code)

class DAL_MovementJournal {       public static void main( Args _args)     {