Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Wednesday, June 22, 2022

Orig() in AX / D365

 Hi,


Orig() is to get the last saved values. This method is used to compare the new values with last saved values.


if(purchTable.orig().DlvTerm != purchTable.DlvTerm)
    {
        //element.updateDlvTerm();
        //Your custom code
}


Regards,

Tuesday, June 21, 2022

Overlayer/Override a methods in D365

 Hi,


Overlayer of standard code to execute your methods is not possible literally, whereas there are several other ways to override.

Procedure.

1. Class to register the override you created.

2. Call the registered call on the eventHander.

Registering Override method.

/// <summary>
/// Custom class created by MAI on 6/21/2022
/// to register the <c>Purchtable</c> form.
/// </summary>
public class PurchTableEventHandler
{
    /// <summary>
    /// Post event handler for <c>Purchtable</c> Initialized event.
    /// </summary>
    /// <param name=“_sender”></param>
    /// <param name=“_e”></param>
    [FormDataSourceEventHandler(formDataSourceStr(PurchTable, PurchTable), FormDataSourceEventType::Initialized)]
    public static void PurchTable_OnInitialized(FormDataSource _sender, FormDataSourceEventArgs _e)
    {
        var overrides = PurchTableFormExtensionOverrides::construct();
 
        _sender.object(fieldNum(PurchTable, CashDisc)).registerOverrideMethod(methodStr(FormDataObject, validate),
            methodStr(PurchTableFormExtensionOverrides, CashDisc_OnValidate), overrides);
    }
}

Calling the Registered methods.

/// <summary>
/// Calling override classes <c>PurchTable</c> data source field methods.
/// </summary>
public class PurchTableFormExtensionOverrides
{
    protected void new()
    {
    }
 
    /// <summary>
    /// Constructs a new instance of <c>PurchTableFormExtensionOverrides</c> .
    /// </summary>
    /// <returns>
    /// new of  <c>PurchTableFormExtensionOverrides</c> class.
    /// </returns>
    public static PurchTableFormExtensionOverrides construct()
    {
        return new PurchTableFormExtensionOverrides();
    }
 
 
    /// <summary>
    /// Checks whether <c>CashDisc</c> is valid.
    /// </summary>
    /// <param name = "_targetField"> The <c>FormDataObject</c> where the Validate is triggered.</param>
    public boolean CashDisc_OnValidate(FormDataObject _targetField)
    {

        boolean ret = _targetField.validate();
 
        if (ret)
        {
            //Your code
        }
 
        return ret;
    }
}

Regards,



Calling custom method of other layer objects created in form level in D365

 Hi,


Using an event handler, we cannot call the custom methods created in another later / model/ ISV object. 

On calling formRun.CreateDeliveryNote()  throws the error ‘FormRun doesn't have the method CreateDeliveryNote.

FormDataSource purchTable_ds = sender.datasource();
FormRun formRun = purchTable_ds.formRun();
formRun.CreateDeliveryNote() ;

Conclusion is to use only COC not eventhandler

[ExtensionOf(formDataFieldStr(PurchTable, PurchTable, DeliveryDate))]
final class PurchTableDeliveryDateField_Extension
{
    public void modified()
    {
         next modified();
         element.CreateDeliveryNote(); // Custom method from Other Later / Model 
    }
}


Regards

Sunday, June 19, 2022

Exdends property of D365

Hi,


To know the ISV objects implications.


[ExtensionOf(classStr(ClassToExtend))] - class

[ExtensionOf(formstr(FormToExtend))] - Forms and its methods

[ExtensionOf(formdatasourcestr(FormToExtend, DataSource1))] - Form Datasource and its methods

[ExtensionOf(formdatafieldstr(FormToExtend, DataSource1, Field1))] - Form Datasource fileds and its methods

[ExtensionOf(formControlStr(FormToExtend, Button1))] - Form Object and its methods

[ExtensionOf(tablestr(TableToExtend))] - Table methods

[ExtensionOf(tableStr(DataEntityToExtend))] - Entity methods


Regards,

Thursday, June 16, 2022

Count the no of rows updated using update_recordset in AX 2012/D365

Hi,

static void Job560(Args _args)
{
    PurchLine       purchLine;
    PurchTable      purchTable;
 
    update_recordset purchLine
        setting
            CustomerRef = "CUST_0012"
        join PurchTable
            where PurchTable.PurchId == "PO-000368"
            && PurchTable.PurchId == purchLine.PurchId
             && purchLine.CustomerRef == "";
    info(strFmt("PurchTable = %1, PurchLine = %2 records updated",purchTable.RowCount(),purchline.RowCount()));
}


Regards,

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...