Sunday, August 30, 2020

Reverse Customer bank transactions by X++ code

 

Hi guys,Today we see how to Reverse transaction by X++ code.


Here I wrote 2 codes.Try Any one

Code 1:

void clicked()

{

    CustTrans     custTransLocal;

    Args          args;

    str           reasonCode;

    ReasonTable   reasonTable;

    RecId         reasonRefRecID;

    BankPaymCancel bankPaymCancel;


    reasonCode = "ERROR";

    reasonTable = ReasonTable::find(reasonCode);

    reasonRefRecID = ReasonTableRef::createReasonTableRef(

    reasonTable.Reason, reasonTable.Description);




    select CustTransLocal

            where CustTransLocal.AccountNum == 'US-004'

                && CustTransLocal.Voucher == 'ARPM000784';

    


    args = new Args();


    bankPaymCancel = BankPaymCancel::newBankPaymCancel(CustTransLocal);


    bankPaymCancel.parmReason(reasonTable.Reason);

    bankPaymCancel.parmReasonComment(reasonTable.Description);

    bankPaymCancel.parmTransDate(systemDateGet());


    args.caller(bankPaymCancel);

    args.record(CustTransLocal);

    BankPaymCancel::serverRun(args);

    super();

}


Code 2:


void clicked()

{

    CustTrans                 CustTransLocal;

    TransactionReversal_Cust  transactionReversal_Cust;

    Args   args;

    

    

    select CustTransLocal

        where CustTransLocal.AccountNum == 'US-004'

            && CustTransLocal.Voucher == 'ARPM000785';

    

    if(CustTransLocal)

    {

        transactionReversal_Cust = new TransactionReversal_Cust();

        args = new Args();

        args.record(CustTransLocal);

        transactionReversal_Cust.parmReversalDate(systemdateget());

        

        transactionReversal_Cust.reversal(args);

    }

}


Keep Daxing!!


Friday, August 28, 2020

How to add a Field and a Method to a standard Table in D365 F & O/AX 7

 

Hi guys ,Today we see how to add a field and Method to a standard Table in D365.


In D365 EXTENSIONs concept is  added.In 2012  only layering concept.

ADD Field :

Run visual studio As Administrator.

Click on Application Explorer.

Right click on CustGroup Table and click on Create extension.

Table add to your Project with '.modelsuffix.

Add field in CustGroup table


ADD Method :

      For creating method we Have to create Class and that class 

  • must be final.
  • must be suffixed by _Extension.
  • must be decorated with the [ExtensionOf()] attribute.
Code

[ExtensionOf(tableStr(CustGroup))]

final class CustGroup_Extension

{

    public void insertName()

    {

        this.name= this.CustGroup;

    }

}


By using Event Handler We are adding this method to Modified Method of CustGroup Table.

For that we have to create Event Handler Class.


class CustGroup_EventHandler

{

    [DataEventHandler(tableStr(CustGroup), DataEventType::ModifiedField)]

    public static void CustGroup_onInserting(Common sender, DataEventArgs evnetArgs)

    {

        CustGroup custGroup = sender as CustGroup;

        CustGroup.insertName();

    }

}


Keep Daxing!!







Friday, August 21, 2020

How to remove special characters from a string in AX 2012 using X++


Hi guys ,Today we see How to remove special characters from a string in Ax 2012 X++.

For this we have Multiple ways :
1.Using StrRem function.
2.Using Standard Class Replace method.
3 Developing some logic.

And 2 more we have.
4.Using strkeep function.
5.Using strAlpha fonction.

The above 2 functions will Remove all Special characters from  string.
In this blog I remove these special characters-'  ','/','_'(space,slash,Under score)
Just check Below code.

1.Using 'StrRem' function:

void clicked()
{
    str name = TextStringEdit.valueStr();
    name=strRem(name,' '+'/'+'_');

    info(name);
}


2.Using 'Standard Class Replace' method:

void clicked()
{
    str name = TextStringEdit.valueStr();
    name=System.Text.RegularExpressions.Regex::Replace(name, @"[/ _]", "");

    info(name);
}

3.Developing 'some logic':

void clicked()
{
    str name = TextStringEdit.valueStr();
    str replace(str _source, str _what, str _with)
    {
        int found = 0;
        str target = _source;
        ;
        do
        {
            found = strscan(target, _what, found, strlen(target));
              
            if (found != 0)
            {
                target = strdel(target, found, strlen(_what));
                target = strins(target, _with, found);
                found += strlen(_with);
            }
        } while (found != 0);
                return target;
    }
    ;

    name = replace(name, '/', "");
    name = replace(name, '_', "");
    name = replace(name, ' ', "");
    
    info(name);

}

4.Using 'strkeep'function:(It prints only A-Z)

void clicked()
{
    str name = TextStringEdit.valueStr();
    name=strkeep(TextStringEdit.text(), "ABCDEFGHIJKLMNOPQRSTUVWXYZ");

    info(name);
}


5.Using 'strAlpha' fonction:(It prints only Alpha Numeric values)

void clicked()
{
    str name = TextStringEdit.valueStr();
    name=strAlpha(TextStringEdit.valueStr());

    info(name);
}



Output:


The above screen shot is the output for 1,2,3.

Keep Daxing !!