Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Tuesday, 26 November 2019

D365 Parameter Table code

D365 Parameter Table code
Below are the find and exist methods of the parameter table.

public static ParameterTable find(boolean _forupdate = false)
    {
        ParameterTable parameter;

        if (_forupdate)
        {
            parameter.selectForUpdate(_forupdate);
        }

        select firstonly parameter
            index hint KeyIdx
            where parameter.Key == 0;

        if (!parameter && !parameter.isTmp())
        {
            Company::createParameter(parameter);
        }
        return parameter;
    }

    public static boolean exist()
    {
        return (select firstonly RecId from ParameterTable).RecId != 0;
    }

Friday, 11 October 2019

BP Error 'parameter not used' fix

BP Error 'parameter not used' fix

Many times you come across the error after compiling.
The best solution is to remove the parameter in case it is not required because if it is not used then why declare it.
However in many cases while extension you need the paramtere and hence if you want to supress this error then you can use the following code ..place it above the method within the attiributes and you wont get the error.

SuppressBPWarning('BPParameterNotUsed', "Parameter required" 
[FormDataFieldEventHandler(formDataFieldStr(SalesForm, Datasource, Field), FormDataFieldEventType::Validating),SuppressBPWarning('BPParameterNotUsed', "Parameter required")
]
{
///code here
}

Thanks,
Vikas Mehta.

Thursday, 10 October 2019

HOW TO SELECT MULTIPLE VALUES IN ENUMS IN D365 CODE

HOW TO SELECT MULTIPLE VALUES IN ENUMS IN D365 CODE

Below code is used to select multiple enum values in a while loop via a container..

SalesTable  salesTable;
container   con = [SalesType::Sales, SalesType::ReturnItem];
while select SalesId from salesTable
where salesTable.SalesType in con
{
Info(salesTable.SalesId);
}

THanks,
Vikas Mehta.

Wednesday, 9 October 2019

Code to change to Accounting currency in D365 Dynamics ax


Code to change to Accounting currency in D365 Dynamics ax 

Currency::amount(markupTrans.Value, markupTrans.CurrencyCode);

In the above code you can use any other table having corresponding values eg.salestrans.

Thanks,
Vikas Mehta.

CREATE AND POST PRODUCTION ROUTE JOURNAL USING PRODUCTION ORDER

CREATE AND PRODUCTION ROUTE JOURNAL USING PRODUCTION ORDER

static void createRouteCardJournalSample(Args _args)
{
    ProdJournalTable                      prodJournalTable;
    ProdJournalRoute                     prodJournalRoute;
    ProdRoute                               prodRoute;
    ProdId                                     prodId     = 'PO001';
    OprNum                                  oprNum   = 20;
    RouteOprId                              routeOprId;
    ProdJournalCheckPostRoute     prodJournalCheckPostRoute;

    select firstonly prodRoute
                where prodRoute.ProdId == prodId  && prodRoute.OprNum == oprNum;

    prodJournalTable.clear();
    prodJournalTable.initValue();
    prodJournalTable.JournalType            = prodjournaltype::RouteCard;
    prodJournalTable.ProdId                     = prodId;
    prodJournalTable.JournalNameId       = ProdParametersDim::findDefault().RouteJournalNameId;
    prodJournalTable.Description             =                                                  ProdJournalName::find(prodJournalTable.JournalNameId).Description;
    prodJournalTable.VoucherSeqRecId   = ProdJournalName::find(prodJournalTable.JournalNameId).VoucherSeqRecId;
    prodJournalTable.VoucherDraw        = journalVoucherDraw::Post;
    prodJournalTable.NumOfLines         = 1;
    prodJournalTable.insert();

    //Route card entry
    prodJournalRoute.clear();
    prodJournalRoute.JournalId               = prodJournalTable.journalId;
    prodJournalRoute.ProdId                   = prodId;
    prodJournalRoute.initValue();
    prodJournalRoute.OprNum               = oprNum;
    prodJournalRoute.OprId                    = prodRoute.OprId;
    prodJournalRoute.JobType                = RouteJobType::Process;
    prodJournalRoute.CategoryHoursId  = prodRoute.SetUpCategoryId;
    prodJournalRoute.CategoryQtyId      = prodRoute.ProcessCategoryId;
    prodJournalRoute.DefaultDimension = prodRoute.DefaultDimension;
    prodJournalRoute.WrkCtrId               = prodRoute.WrkCtrIdCost;
    prodJournalRoute.QtyGood               = 2;
    prodJournalRoute.Hours                    = 1;
    prodJournalRoute.insert();
    info(prodJournalTable.JournalId);
 
    ProdJournalCheckPostRoute = ProdJournalCheckPostRoute::newPostJournal(prodJournalRoute.journalId,true);
    ProdJournalCheckPostRoute.run();
}

Thursday, 3 October 2019

remove special character from a string in ax d365

remove special character from a string in ax d365

Below is a very simple trick to remove the special character from any string .

Static str removeSpecialcharacter(str _InputString)
{
   str message;
   message =  System.Text.RegularExpressions.Regex::Replace(_InputString, @"[\W_]", "");
   return message;
}
You can also use below
strRem(words,"\"" + "\t" + "\r" + "\n" + "\r\n" + "\\" +"\b" + "\f");

Thanks,
Vikas Mehta


Thanks,
Vikas Mehta.

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++

Blog Post 6: Bonus – Building Your First Custom Copilot Plugin in X++  Introduction In our previous posts, we explored what Copilot can do o...