Monday, December 7, 2020

ADD Lookup, Disable Dialog field using UI builder in D365FO/Ax7


 Hi guys, Today we see how to ADD Lookup, Disable Dialog field using UI builder in D365FO/Ax7.


UiBuilder Class:

class PriceDiscUiBuilder extends             SysOperationAutomaticUIBuilder //SrsReportDataContractUIBuilder

{

    PriceDiscDataContract priceDiscDataContract;

 

    Public void build()

    {

        priceDiscDataContract = this.dataContractObject();

        this.addDialogField(methodStr(PriceDiscDataContract, parmPriceDiscJournalNum), priceDiscDataContract).allowEdit(false);// Disable the field

        this.addDialogField(methodStr(PriceDiscDataContract, parmPostedPriceDiscJournalNum ), priceDiscDataContract);

    }


    Public void lookupPostJour(FormStringControl _formStringControl)

    {

        Query                   query = new Query();

        QueryBuildDataSource    qbds;

        QueryBuildRange         qbr;

        SysTableLookup          lookup;


        lookup = SysTableLookup::newParameters(tableNum(PriceDiscAdmTable), _formStringControl);


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

        qbr=qbds.addRange(fieldNum(PriceDiscAdmTable, Posted));

        qbr.value(SysQuery::value(NoYes::Yes));

        lookup.parmQuery(query);


        lookup.addLookupfield(fieldNum(PriceDiscAdmTable, JournalNum));

        lookup.addLookupfield(fieldNum(PriceDiscAdmTable, JournalName));

        lookup.performFormLookup();

    }


    Public void PostBuild()

    {

        DialogField postedJourNum;


        postedJourNum=this.bindInfo().getDialogField(this.dataContractObject(),

                                            methodStr(PriceDiscDataContract,parmPostedPriceDiscJournalNum));

        postedJourNum.registerOverrideMethod(methodStr(FormStringControl, lookup),

                                            methodStr(PriceDiscUiBuilder, lookupPostJour), this);

    }

}


Contract Class:


[DataContractAttribute,

    SysOperationContractProcessingAttribute(classstr(PricediscUiBuilder))]

public class PriceDiscDataContract

{

    str                     priceDiscJournalNum;

    PriceDiscJournalNum     postedPriceDiscJournalNum;

 

    [DataMemberAttribute,

    sysoperationh('Current journal number'),

    SysOperationHelpTextAttribute('Enter journal number')]

//SysOperationControlVisibilityAttribute(false)// Hide control

    public str parmPriceDiscJournalNum(str _priceDiscJournalNum = priceDiscJournalNum)

    {

        priceDiscJournalNum = _priceDiscJournalNum;

        return priceDiscJournalNum;

    }


    [DataMemberAttribute,

    SysOperationLabelAttribute('Posted journal number'),

    SysOperationHelpTextAttribute('Enter journal number')]

    public PriceDiscJournalNum parmPostedPriceDiscJournalNum(PriceDiscJournalNum _priceDiscJournalNum = postedPriceDiscJournalNum)

    {

        postedPriceDiscJournalNum = _priceDiscJournalNum;

        return postedPriceDiscJournalNum;

    }

}

OutPut:

Keep Daxing!!




Display and Edit methods in D365 FO


 Hi guys, Today we see How to add the Display method, Edit method In the standard Table Using COC in D365 FO / AX 7.


Check Below Example:


[ExtensionOf(tableStr(CustGroup))]

final class CustGroup_Extension

{

    [SysClientCacheDataMethod(true)]

    display Name displayName()

    {

        return this.CustGroup + ' ' + this.PaymTermId;

    }


    Edit Name editName(boolean _set, Name _name)

    {

        Name            name    = _name;

        CustDemo        custDemo;

        ;

        if(_set)

        {

            if(name)

            {

                ttsbegin;

                custDemo = CustDemo::find(this.CustGroup,true);

                custDemo.Name  = name;

                custDemo.update();

                ttscommit;

            }

        }

        else

        {

            name    = CustDemo::find(this.CustGroup).Name;

        }

        return name;

    }

}

Create a new field in the grid. Set the data source and data method properties.

Extension methods are not visible using the drop-down,   so you use a special syntax with the style ExtensionClassName::DisplayMethod.

Keep Daxing!!

Adding Code in Standard Table using COC(Chain of command) in AX7/D365fo

 

Hi guys, Today we see how to Add Code in Standard Table using COC in AX7/D365fo.


Check the Below Example.

[ExtensionOf(tableStr(CustGroup))]
Final class CustGroup_Extension
{
    [SysClientCacheDataMethod(true)]
    display Name displayName()
    {
        return this.CustGroup + ' ' + this.PaymTermId;
    }

    void initValue()
    {
        // pre event
        next initValue();
        //Post event

        this.NoYes = NoYes::Yes;
    }

    public void modifiedField(FieldId _fieldId)
    {
        next modifiedField(_fieldId);

        switch (_fieldId)
        {
            case fieldnum(CustGroup, NoYes):
                this.PriceIncludeSalesTax = this.NoYes == NoYes::Yes ? 
                                                NoYes::Yes : NoYes::no;
                break;
        }
    }

    public boolean validateWrite()
    {
        boolean ret = next validateWrite();

        if(!this.TaxGroupId)
        {
            ret = checkFailed('Tax group is mandatory');
        }

        return ret;
    }

    public boolean validateField(FieldId _fieldIdToCheck)
    {
        boolean ret;

        ret = next validateField(_fieldIdToCheck);

        switch (_fieldIdToCheck)
        {
            case fieldnum(CustGroup, Name):
                if (this.NoYes == NoYes::Yes)
                {
                    if(this.Name =="")
                    {
                        ret = ret && checkFailed('when check box is yes
                                this field is mandatory');
                    }
                }
        }

        return ret;
    }
}


Keep Daxing!!

Passing Values to Data contract class in AX7/ D365 fo

 

Hi guys, Today we see how to Pass Values to Data contract class in AX7/ D365 fo.


I am passing the values from 'From Clicked method' to 'Data contract class' by Controller Class. 

Check the below example:


void clicked()

{

    SysOperationController            controller;

    SysOperationDataContract          dataContract;


    controller = new SysOperationController();


    controller.parmLoadFromSysLastValue(false);

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

            //controller.getDataContractObject()//// for sys operation     //controller.parmReportContract().parmRdpContract()

    dataContract = controller.getDataContractObject('_contract'); // In service class in processOperation method we are declaring  DataContact as Variable. That variable buffer we have to declare here. Method Signature Ex: public void processOperation(SysOperationDataContract  _contract)


    dataContract.parmCustAccount(CustTable.AccountNum);// passing value


    controller.startOperation();

}

Getting caller Record in Sys Operation Click Here.

Keep Daxing!!

How to Get caller record in SysOperation in AX7/D365 fo

 

Hi guys, Today we see how to Get caller record in Sys operation Controller class in AX7/D365 fo.


Check the below class:


[SysOperationJournaledParametersAttribute(true)]

class DaxPriceDiscController extends SysOperationServiceController

{

    Common                      callerRecord;

    DAXPriceDiscDataContract    daxPriceDiscContract;

    PriceDiscAdmTable           priceDiscAdmTable;

    PriceDiscAdmTrans           priceDiscAdmTrans;


    public Common parmCallerRecord(Common _callerRecord = callerRecord)

    {

        callerRecord = _callerRecord;


        return callerRecord;

    }


    private void initFromCaller()

    {

        daxPriceDiscContract = this.getDataContractObject();


        switch (this.parmCallerRecord().TableId)

        {

            case tableNum(PriceDiscAdmTrans) :

                priceDiscAdmTrans = this.parmCallerRecord() as PriceDiscAdmTrans;


                daxPriceDiscContract.parmPriceDiscJournalNum(priceDiscAdmTrans.journalnum);

            break;

        }

    }


    public static DaxPriceDisccontroller newFromArgs(Args _args)

    {

        IdentifierName                  className;

        IdentifierName                  methodName;

        SysOperationExecutionMode       executionMode;

        DaxPriceDisccontroller          controller;


        [className, methodName, executionMode] = SysOperationServiceController::parseServiceInfo(_args);


        if (_args.record())

        {

            executionMode = SysOperationExecutionMode::Synchronous;

        }

        controller = new DaxPriceDisccontroller(className, methodName, executionMode);

        controller.parmArgs(_args);

        controller.parmCallerRecord(_args.record());


        return controller;

    }


    protected void refreshCallerRecord()

    {

        FormDataSource callerDataSource;

        if (this.parmCallerRecord() && this.parmCallerRecord().dataSource())

        {

            callerDataSource = this.parmCallerRecord().dataSource();

            callerDataSource.research(true);

        }

    }


    void new(IdentifierName _className = classStr(DaxPriceDiscService),

            IdentifierName _methodName = methodStr(DaxPriceDiscService, insertLines),

            SysOperationExecutionMode _executionMode = SysOperationExecutionMode::Synchronous)

    {

        super(_className, _methodName, _executionMode);


        this.parmClassName(classStr(DaxPriceDiscService));

        this.parmMethodName(methodStr(DaxPriceDiscService, insertLines));

    }


    Public static void Main(Args _args)

    {

        DaxPriceDiscController daxPriceDiscController= new DaxPriceDiscController();

        daxPriceDiscController = DaxPriceDiscController::newFromArgs(_args);

        daxPriceDiscController.initFromCaller();

        daxPriceDiscController.refreshCallerRecord();

        daxPriceDiscController.startOperation();

    }


    public DAXPriceDiscDataContract parmDaxPriceDiscContract(DAXPriceDiscDataContract _daxPriceDiscContract = daxPriceDiscContract)

    {

        daxPriceDiscContract = _daxPriceDiscContract;

        return daxPriceDiscContract;

    }

}


Keep Daxing!!

how to write validateField method in Dynamics AX 7, d365

 

Hi guys, Today we see How to write validateField method in Dynamics AX 7, d365.


Check Below class.


class CustTable_Events

{

// Using On Events

    /// <summary>

    ///

    /// </summary>

    /// <param name="sender"></param>

    /// <param name="e"></param>

    [DataEventHandler(tableStr(CustTable), DataEventType::ValidatedField)]

    public static void CustTable_onValidatedField(Common sender, DataEventArgs e)

    {

        ValidateFieldEventArgs event = e as ValidateEventArgs;

        CustTable custTable = sender as CustTable;

    }


// Using Post EventHandler

    /// <summary>

    ///

    /// </summary>

    /// <param name="args"></param>

    [PostHandlerFor(tableStr(CustTable), tableMethodStr(CustTable, validateField))]

    public static void CustTable_Post_validateField(XppPrePostArgs args)

    {

        CustTable custTable     = args.getThis();   //getting table buffer

        FieldId fieldId              = args.getArg("p1"); // Variable buffer

        boolean ret                   = args.getReturnValue(); // get return value from standard method


        switch(fieldId)

        {

            case fieldNum(CustTable, AccountNum):

                if (strLen(custTable.AccountNum) <= 3)

                {

                    ret = ret && checkFailed("Account number should be more than 3 charecters.");

                }

                break;

        }

        args.setReturnValue(ret); // set the return value of this method to standard

    }


Keep Daxing!!

Friday, December 4, 2020

Remove special characters of Date and Time in ax 2012 X++

Hi guys, Today we see how to  Remove special characters of Date and Time in ax 2012 X++.


Run the below job.



 static void FormatDateTimeJob(Args _args)

{

    utcDateTime now = DateTimeUtil::utcNow();


    str formattedOutput;


    now = DateTimeUtil::applyTimeZoneOffset(

    now,

    DateTimeUtil::getClientMachineTimeZone());


    formattedOutput = DateTimeUtil::toFormattedStr(

        now,

        321,

        DateDay::Digits2,

        DateSeparator::None,

        DateMonth::Digits2,

        DateSeparator::None,

        DateYear::Digits2,


        TimeSeparator::Colon,

        TimeSeparator::Colon);


    info(formattedOutput);

    info(strRem(formattedOutput,":"+" "));

}

OutPut:







Keep Daxing!!

Thursday, December 3, 2020

Change LinkType on FormDatasource in AX7 / D365

 

Hi guys, Today we see how to change LinkType on FormDatasource in AX7 / D365.


In this post I change the link type of salesline Table in SalesTable Form without overlayring.

/// <summary>

/// 

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

[FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Initialized)]

public static void SalesLine_OnInitialized(FormDataSource sender, FormDataSourceEventArgs e)

{      

    sender.queryBuildDataSource().joinMode(joinMode::OuterJoin); 

}

Keep Daxing!!


Get Open Closed Transactions of selected customer in Ax 2012 using x++

 Hi guys, Today we see how to get Open Closed Transactions of selected customer in Ax 2012 using x++.

Run the below job.

static void OpenClosedTransactions(Args _args)

{

    CustTable       custtable;

    CustTrans       custtrans;

    CustTransOpen   custtransopen;

    CustSettlement  custsettlement;


    //OpenTransactions


    while  select custtable

        where custtable.AccountNum == 'US-004'

    join custtrans

        where  custtable.AccountNum == custtrans.AccountNum

    join  custtransopen

        where custtrans.RecId == custtransopen.RefRecId

    {

        info(strfmt('%1,%2,%3,%4,%5',custtable.AccountNum,custtrans.Voucher,custtransopen.AmountCur,custtrans.TransDate,custtransopen.DueDate));

    }


    //ClosedTransactions


    while  select custtable

        where custtable.AccountNum == 'US-004'

    join custtrans

        where  custtable.AccountNum == custtrans.AccountNum

    join  custsettlement

        where custtrans.RecId == custsettlement.TransRecId

    {

        info(strfmt('%1,%2,%3,%4,%5',custtable.AccountNum,custtrans.Voucher,custsettlement.settleAmountCur,custtrans.TransDate,custsettlement.DueDate));

    }


    //sum of open and closed transactions


     while select sum(settleAmountCur) from custsettlement

        where custsettlement.AccountNum == 'US-010'

    {

        info(strfmt('%1',custsettlement.settleAmountCur));

    }



     while select sum(AmountCur) from custtransopen

        where custtransopen.AccountNum == 'US-010'

    {

        info(strfmt('%1',custtransopen.AmountCur));

    }

}

Keep Daxing!!