Monday, November 27, 2023

Code to Populate Custom field data from PurchTable to VendInvoiceJour in D365 f&o X++

[ExtensionOf(tableStr(VendInvoiceJour))]

public final class DaxVendInvoiceJour_Extension

{

   public void insert()

   {

       PurchTable      purchTable = PurchTable::find(this.PurchId);

       this.Dax_Remarks = purchTable.Dax_Remarks;

       next insert();

   }

}

...............

OtherWay:

[ExtensionOf(classStr(FormletterService))]

 internal final class DaxFormLetterServiceClass_Extension

 {

    protected void processJournal(Printout _printout)

    {

         VendInvoiceJour         vendInvoiceJourlocal;

         PurchTable              purchTable;

         next processJournal(_printout);

        select forupdate vendInvoiceJourlocal 

            join purchTable

                where vendInvoiceJourlocal.ParmId == parmId

                && vendInvoiceJourlocal.purchId == purchTable.purchId;

        ttsbegin;

        vendInvoiceJourlocal.Dax_Remarks = purchTable.Dax_Remarks; // custom field

        vendInvoiceJourlocal.update();

        ttscommit;

     }

 }

.........................

Other Way :

[ExtensionOf(classStr(PurchFormLetter_Invoice))]

internal final class DaxPurchFormLetter_Invoice_Extension

{

   protected void runRemainUpdates()

   {

       VendInvoiceJour     vendInvoiceJour;

       PurchTable          purchTable;

       str parmid = this.parmId();

       next runRemainUpdates();

       select forupdate vendInvoiceJour

           where vendInvoiceJour.ParmId == parmid;

       purchTable = PurchTable::find(vendInvoiceJour.PurchId);

       ttsbegin;

       vendInvoiceJour.Dax_Remarks = purchTable.Dax_Remarks;

       vendInvoiceJour.update();

       ttscommit;

   }

}

Output :


    





How to make grid empty based on conditions in D365 f&o X++

 I have grid with purchline datasource.

If the location is empty . Then grid should be empty.(no records in gird)

If the location has some range. then range should be applied on grid.


 QueryBuildDataSource            qbdspurch;

 QueryBuildRange                       qbr;

if(this.daxlocation)

{

                 qbdspurch = this.query().dataSourceTable(tableNum(PurchLine));

                    qbr = qbdspurch.addRange(fieldNum(PurchLine, daxlocation));

                    qbr.value(this.daxlocation);

}

else

{

                     qbdspurch = this.query().dataSourceTable(tableNum(PurchLine));

                    qbr = qbdspurch.addRange(fieldNum(PurchLine, PurchId));

                    qbr.value(SysQuery::valueEmptyString()); //makes grid empty

}

reference blog:

https://daxingwitheshant.blogspot.com/2015/04/how-to-filter-gird-based-on-given-input.html

Monday, November 6, 2023

Code to create a Simple BatchJob with Records to include filter in D365F&O X++

/// <summary>

/// The <c>MCRFTCEventProcessBatch</c> class handles processing FTC events in batch.

/// </summary>

class MyBatchJobBatch extends RunBaseBatch implements BatchRetryable

{

   // Packed variables

   int                 dummy;

   // Dialog fields

   QueryRun                            projectQueryRun;

 

   #define.CurrentVersion(2)

   #localmacro.CurrentList

       dummy,

       startDate,

       endDate

   #endmacro

   /// <summary>

   /// Adds the <c>SalesID</c> to the dialog box

   /// allowing the user to run a batch over the selected

   /// <c>SalesID</c>.

   /// </summary>

   /// <returns>

   /// The dialog box box.

   /// </returns>

   public Object dialog()

   {

       DialogRunbase               dialog; 

       //Setup the dialog

       dialog = super();

       dialog.caption("Simple Batch Job");

       return dialog;

   }

   /// <summary>

   /// Retrieves the user entered values from dialog form.

   /// </summary>

   /// <returns>

   /// true if the values are retrieved successfully; otherwise, false.

   /// </returns>

   public boolean getFromDialog()

   {

       boolean ret;

       ret = super();

       return ret;

   }

   protected void initQuery()

   {

       QueryBuildDataSource qbds;

       Query                query = new Query();

 

       query.allowCrossCompany(true);

       qbds = query.addDataSource(tableNum(CustTable));

       projectQueryRun = new QueryRun(query);

   }

   protected void new()

   {

       super();

       this.initQuery();

   }

   public container pack()

   {

       return [#CurrentVersion, #CurrentList];

   }

   boolean prompt()

   {

       return super();

   }

   public QueryRun queryRun()

   {

       return projectQueryRun;

   }

   public boolean showQueryValues()

   {

       return true;

   }

   public boolean unpack(container packedClass)

   {

       Version version = runbase::getVersion(packedClass);

       switch (version)

       {

           case #CurrentVersion:

               [version, #CurrentList] = packedClass;

               break;

           default:

               return false;

       }

       return true;

   }

    public static MCRFTCEventProcessBatch construct()

   {

       return new MCRFTCEventProcessBatch();

   }

   public static ClassDescription description()

   {

       return "Simple Batch Job";

   }

   public static void main(Args args)

   {

       MyBatchJobBatch myBatchJobBatch = new myBatchJobBatch();

       myBatchJobBatch.parmInBatch(false);

 

       if (myBatchJobBatch.prompt())

           myBatchJobBatch.runOperation();

   }

 

   /// <summary>

   /// Describes whether the class is designed for execution in a new session.

   /// </summary>

   /// <returns>

   /// false.

   /// </returns>

   protected boolean canRunInNewSession()

   {

       return false;

   }

   /// <summary>

   /// Specifies if the batch task is retryable for transient exceptions or not.

   /// </summary>

   /// <returns>

   /// If true is returned, the batch task is retryable, otherwise it is not.

   /// </returns>

   [Hookable(false)]

   final boolean isRetryable()

   {

       return true;

   }

}

Output :