Translate

Wednesday, June 26, 2019

Open a Purchtable form through info log in AX 2012

How to open Purchtable form from the Info Log.

static void viewPOthroughInfo(Args _args)
{
    PurchTable  purchTable;
 
    purchTable = PurchTable::find("PO-000001852");
 
    info(strFmt("@PAC51058",purchTable.PurchId),"", SysInfoAction_TableField::newBuffer(purchTable));
}


Now click and show button, it will navigate to Purchtable form for the PO number.

 

Job to get distinct display product number in D365FO

 In this blog, I will discuss how to get a distinct display product number in Dynamics 365 Finance and Operations. Please see the screenshot below with the source code explanation.


Note: In my case, I have got Item Id and Invent Dim Id from RFQ Lines.

Explanation of source code (1.1):
  • Get a purchase request for quotation from RFQCaseId and LineNum.
  • Updating inventory dimensions.
  • Find or create an inventory dimension.
  • Find the inventory dimension combination is order to get the product variant record ID.
  • Get the display product number and set it in the info method.

class JobToGetDisplayProductNumber
{
    /// <summary>
    /// In this job we are getting display product number by
    /// Item Id and Invent Dim Id.
    /// </summary>
    /// <param name = "args">The specified arguments.</param>
    public static void main(Args _args)
    {

        PurchRFQCaseLine         line;

        InventDim                inventDim;
        InventDimCombination     inventDimComb;
 
        //Get purchase request for quotation line from RFQId and LineNum
        line = PurchRFQCaseLine::find('CDPL-000051', 3);
         
        //Updating inventory dimensions
        inventDim = line.inventDim();
        inventDim.InventSiteId = '';
        inventDim.InventLocationId = '';
 
        //Find or Create inventory dimensions
        inventDim = InventDim::findOrCreate(inventDim);
 
        //Find inventory dimension combination in order to get Product Variant Record Id
        inventDimComb = InventDimCombination::findByInventDim(line.ItemId, inventDim);

 

        //Display product from <c>EcoResDistinctProductVariant</c> table.
        info(EcoResDistinctProductVariant::find(inventDimComb.DistinctProductVariant).DisplayProductNumber);
    }
}


Abstract Class and Abstract Method in AX

Abstract Class:

Abstract classes are classes that contain one or more abstract methods.

An abstract method is a method that is declared but contains no implementation.

When we declare a class as abstract, this class cannot be instantiated in X++ code. To use this class or its method, we have to first extend this class, then only we are able to use this class or its method.

This is often used in the standard package for superclasses to control that the superclass is not declared by mistake. 

The class SalesFormLetter which is used for creating documents such as sales confirmations and sales invoices uses this practice. 

The class has an construct() method which should be used, and to prevent the class being declared using new() 

SalesFormLetter is qualified as abstract.



To understand the abstract class consider following example

We have three classes
     1.      absClass  (it’s an abstract class)
     2.      normalClass (an another class which will use the absClass methods)
     3.      extendAbsClass (this class will extends the absClass)

    1.abstract class absClass
     {
     }

    void printName()
   {
    ;    info("AbsClass... Deepak");
   }


    2. class extendAbsClass extends absClass
       {
        }

    3.class normalClass
      {
      }

  void accessAbsClass()
{
    absClass        absClass;
    extendAbsClass  extendAbsClass;
    ;
 //   absClass = new absClass();    // this declaration will throw error “Object could not be created because class absClass is abstract” so first we extend absClass into extendsAbsClass and further use extendsAbsClass to access absClass methods.
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.printName();
}


Abstract Method:

When we declare a method as abstract, this method should be overload in child class or we can say , this method  should be declare/initiate in child class, than only we can use this class or its method.
Note:
a.      Abstract methods may only be declared in abstract classes.
b.      No code or declarations are allowed in abstract methods.

We have three classes
i.                    absMethodClass
ii.                  extendAbsClass
iii.                NormalClass

1.      abstract class absMethodClass
{
}

abstract void absPrintName()
{
                        // we cannot declare any code in abstract method
}

2.      class extendAbsClass extends absMethodClass
{
}

void absPrintName()
{
    ; // we have to initiate abstract method here as this class extends the abstract class.
    info("abstract method declaration in derived class");
}
3.      class childClass_1
{
}

void accessAbsClass()
{
    extendAbsClass  extendAbsClass;
    ;
    extendAbsClass  = new extendAbsClass();
    extendAbsClass.absPrintName();

}


Conclusion : 

  • Abstract classes can't be instantiated
  • they're explicitly intended to be extended. 
  • They also usually contain abstract methods, i.e. methods without any implementation that must be implemented by any non-abstract child. 
  • It allows you to define high-level concepts and provide some common functionality and leave details for concrete implementations. 


For example, RunBaseBatch class is abstract - it can't be used by itself because it doesn't define any action to run, but you can extend it and inherit a huge amount of functionality common to all batches.