Monday, July 14, 2025

Multi selection lookup in grid

 [Form]

public class Form1 extends FormRun

{ 

    

     SysLookupMultiSelectCtrl msCtrl;


    [Control("String")]

    class MyTablenew_FieldString2

    {

        

        public void lookup()

        {

           

           

            Query query = new Query();

            QueryBuildDataSource qbds = query.addDataSource(tableNum(MainAccount));         

            qbds.fields().addField(fieldNum(MainAccount, MainAccountId));

            qbds.orderMode(OrderMode::GroupBy);

            qbds.addGroupByField(fieldNum(MainAccount, MainAccountId));

            qbds.fields().dynamic(NoYes::No);

            msCtrl = SysLookupMultiSelectCtrl::constructWithQuery(element,MyTablenew_FieldString2,query);

            

            msCtrl.set(msCtrl.getSelectedFieldValues());

        }


        

        public boolean modified()

        {

            boolean ret;

        

            ret = super();

            MyTablenew buffer=element.dataSource("MyTablenew").cursor();

            buffer.FieldString2=con2Str(msCtrl.getSelectedFieldValues(),";");

        

            return ret;

        }

    }



}


Output:-






Friday, July 11, 2025

Get Mainaccount lookup thorugh lookup code

 Query query = new query();

   QueryBuildDataSource qbds; 
   QueryBuildRange qbr;
   SysTableLookup  sysTableLookup;
   sysTableLookup= SysTableLookup:: newParameters (tableNum (MainAccount),this);
   sysTableLookup.addLookupfield (fieldNum (MainAccount, MainAccountId));
   sysTableLookup.addLookupfield (fieldNum (MainAccount, Name));
   qbds = query.addDataSource(tableNum (MainAccount));
   qbds.orderMode(OrderMode::GroupBy);
   qbds.addGroupByField(fieldNum(MainAccount, MainAccountId));
   qbds.addGroupByField(fieldNum(MainAccount, Name));
   //qbr = qbds.addRange(fieldNum (MainAccount, LedgerChartOfAccounts)); 
   //qbr.value(queryValue (LedgerChartOfAccounts::current()));
   sysTableLookup.parmQuery(query); 
   sysTableLookup.performFormLookup();

Thursday, July 10, 2025

Create and post Free text invoice for customer through code X++

 internal final class TestFreeTextInvoices

{

    /// <summary>

    /// Class entry point. The system will call this method when a designated menu

    /// is selected or when execution starts and this class is set as the startup class.

    /// </summary>

    /// <param name = "_args">The specified arguments.</param>

   

    public static CustInvoiceTable    custInvoiceTable;

    public static CustInvoiceLine custInvoiceLine;

    public static void main(Args _args)

    {

        

        

        TestFreeTextInvoices caption = new TestFreeTextInvoices();

        caption.createCustInvoiceHeader(systemDateGet(),(systemDateGet()+10),'US-001','10');

        if(custInvoiceTable)

        {

            caption.createCustInvoiceLine(custInvoiceTable,'test description','ALL','CA',1,1,'110110');

            if(custInvoiceLine)

            {

                caption.postCustInvoice(custInvoiceTable);

            }

        }

        

        

    }

 

    public CustInvoiceTable createCustInvoiceHeader(TransDate _invoiceDate , DueDate _dueDate, CustAccount _custAccount = '', CustGroupId _custGroup = '')

    {

        CustTable        custTable;

 

        custTable = CustTable::find(_custAccount);

        custInvoiceTable.initFromCustTable(custTable);

        custInvoiceTable.CustGroup                          = _custGroup;

        custInvoiceTable.OrderAccount                       = _custAccount;

        custInvoiceTable.InvoiceAccount                     = _custAccount;

        custInvoiceTable.modifiedField(fieldNum(CustInvoiceTable, OrderAccount));

        custInvoiceTable.InvoiceDate                        = _invoiceDate;

        custInvoiceTable.DueDate                            = _dueDate;

        if(custInvoiceTable.validateWrite())

        {

            custInvoiceTable.insert();

        }

 

        return custInvoiceTable;

    }

    

    public void createCustInvoiceLine(CustInvoiceTable _custInvoiceTable, TransactionTextLarge _description = '', TaxItemGroup _taxItemGroup = '', TaxGroup _taxGroup = '', InvoiceQuantity _qty = 1, InvoiceUnitPrice _unitPrice = 1, str MainAccount ='')

    {

        

        LineNum         lineNum;

        

        custInvoiceLine.initValue();

        custInvoiceLine.initFromCustInvoiceTable(_custInvoiceTable);

        

        custInvoiceLine.Description      = _description;

        custInvoiceLine.TaxItemGroup     = _taxItemGroup;

        custInvoiceLine.TaxGroup         = _taxGroup;

        custInvoiceLine.ParentRecId      = _custInvoiceTable.RecId;

        custInvoiceLine.Quantity         = _qty;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, Quantity));

        custInvoiceLine.UnitPrice        = _unitPrice;

        custInvoiceLine.modifiedField(fieldNum(CustInvoiceLine, UnitPrice));

        custInvoiceLine.AmountCur        = custInvoiceLine.Quantity * custInvoiceLine.UnitPrice;

        custInvoiceLine.LedgerDimension  = TestFreeTextInvoices::findLedgerDimensionByMainAccount(MainAccount);

        

        if(custInvoiceLine.validateWrite())

        {

            custInvoiceLine.insert();

        }

    }

 

    public static RecId findLedgerDimensionByMainAccount(str MainAccount)

    {

        MainAccount mainAccounttest = MainAccount::findByMainAccountId(MainAccount, true);

        DimensionAttributeValueCombination dimensionAttributeValueCombination;


        select firstOnly dimensionAttributeValueCombination

             where dimensionAttributeValueCombination.MainAccount == mainAccounttest.RecId && dimensionAttributeValueCombination.LedgerDimensionType==LedgerDimensionType::DefaultAccount;

        

        

        return dimensionAttributeValueCombination.RecId;

    }

 

    public void postCustInvoice(CustInvoiceTable _custInvoiceTable)

    {

        CustPostInvoice custPostInvoice;

 

        custPostInvoice = new CustPostInvoice(_custInvoiceTable);

 

        ttsbegin;

        custPostInvoice.run();

        ttscommit;

    }

}

OutPut:-



Miscellaneous code

 1) Dimensions  view :- To get all dimension values use this views

DimensionAttributeLevelValueAllView  ---ldger 

DefaultDimensionView   ------------------------default 


---------------------------------- 

2) To access Global declared buffers in methods 

Use "element.buffer" by  this one can get all buffers from global level.  

 

Note:- By just using element. You won't see the buffers list , just copy and paste and save you will see no errors 


-------------------------------------------------------------------------

3) To insert data in TempDB table use snippet shown in below:-


 LedgerVoucherTransAuditLogDetailTmp tembuf;

 str note = "today test";

 ttsbegin;

 tembuf.GeneralJournalAccountEntry=5637144XXX;

 tembuf.Description="Manitest";

 tembuf.doinsert();

 ttscommit;

---------------------------------------------------------------------------------

4) To get user fullname from shortname 

code:-

HcmWorker::find(HcmWorker::userId2Worker(wfTracking.user)).name();

Note:- here wfTracking.user is the buffer i am using

Tuesday, June 17, 2025

Vendor aging report customization

 Scenario:-In this blog we see customization  of Vendor aging report 

Changes to be done at 3 Levels 

1) Duplicate report and customize as per design

2) Give Report name and design name in controller to open your report.

3) Insertion of data to custom fields if any .


Briefing:- 

1) Duplicate report and customize as per design :-

                                    Design as per your requirement.

2) Give Report name and design name in controller to open your report:- 


Extend the method and override with your report design name:-

   protected final str getReportName(VendAgingReportContract _contract)
    {
        str reportNameLocal;
        next getReportName(_contract);

       
        reportNameLocal = ssrsReportStr(MyVendAgingReport, MyDesignWithNoDetailAndNoTransactionCurCopy1);
            
        

        return reportNameLocal;
    }


3) Insertion of data to custom fields if any :-

As in standard we can't insert again just go for update .

public void processReport()
    {
        
        VendAgingReportTmp vendAgingReportTmploc   = this.vendAgingReportTmp;
        VendTable vendTable;
        DirPartyTable dirpartytable;
        next processReport();
      


        while select vendAgingReportTmploc
        {
            ttsbegin;
            vendTable = VendTable::find(vendAgingReportTmploc.AccountNum);
           
           
            vendAgingReportTmploc.selectForUpdate(true);
            vendAgingReportTmploc.Myfield = vendTable.DirPartyTable().Myfield;
            vendAgingReportTmploc.update();
            ttscommit;
        }

Output:-


Thank you!!




Tuesday, November 12, 2024

Get address through code

Get all address of customer:-    

  CustTable                   customertableloc; 

  DirPartyTable               dirpartytableloc;  

 DirPartyLocation             dirPartyLocation; 

  LogisticsLocation            logisticsLocation;  

 Logisticspostaladdress      logisticspostaladdressloc;  


          customertableloc=CustTable::find("US-006"); 

  select dirpartytableloc    where customertableloc.Party == dirpartytableloc.RecId;

while   select dirPartyLocation  where dirPartyLocation.Party==dirpartytableloc.RecId    

          join      logisticsLocation where dirPartyLocation.Location==logisticsLocation.RecId    

   join     logisticspostaladdressloc    where logisticspostaladdressloc.Location == logisticsLocation.RecId  

{

     if(logisticspostaladdressloc.Address)   

      {       

          Info(strFmt("%1 ,%2", customertableloc.AccountNum,logisticspostaladdressloc.Address));   

      }

 }


Get Requester by Purchid through code :-


PurchTable purchTable ;

HcmWorker  hcmWorker;

DirPerson  dirPerson;

DirPartyTable dirPartyTable;


Select purchTable where purchTable.PurchId=="000006"

     join hcmWorker where hcmWorker.RecId==purchTable.Requester

     join dirPerson where dirPerson.RecId == hcmWorker.Person

     join dirPartyTable

     where dirPartyTable.RecId == dirPerson.RecId;

Info(strfmt("%1",dirPartyTable.Name));


Friday, November 1, 2024

Import 2019Visual studio D365fo projects into 2022Visual studio

 Scenario:-In this blog today we see how to import 2019Visual studio  D365fo projects into 2022Visual studio 

Generally we can import 2019Visual studio  D365fo projects in another 2019Visual studio  as well as we can import 2022Visual studio  D365fo projects in another 2022Visual studio. As we know that now Microsoft is using Visual studio2022  so there are some projects which are developed in Visual studio2019.So now if you want to import then you will get an error.

An unexpected error occured during the project import: The imported project"C:\Program Files (x86)\MSBuild\Microsoft\Dynamics\AX\Microsoft.Dynamics.Framework.Tools.BuildTasks.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files (x86)\MSBuild\Microsoft\Dynamics\AX\Microsoft.Dynamics.Framework.Tools.BuildTasks.targets" is correct, and that the file exists on disk.C:\Users\localadmin\source\repos\FinanceOperations1\FinanceOperations1.rnrproj

To get rid of this issue follow below steps .

Step1:-Go to File explorer  in VM. Now click on this PC as shown in below

Step2:-Now click on the folder where your vm located as shown in below

Step3:-Now click on Program Files(x86) folder as shown in below

Step4:-Now click on  MS Build folder as shown in below

Step5:-Now click on  Microsoft folder as shown in below

Step6:-Now click on  Dynamics folder as shown in below

Step7:-Now click on  AX folder as shown in below

Step8:-Now copy the first file as shown in below

Step9:-Now Paste the file as shown in below

Step10:-You can see the file with copy at ending as shown in below

Step11:-Now Rename the file with   Microsoft.Dynamics.Framework.Tools.BuildTasks.targets   as shown in below



Step12:-Its done .Just go back to visual studio  and import project .


As you can see project got imported successfully .Build the project and start developing. 


Thank you !!

Keep Daxing!!


computed column in Dataentity

synatx:-    public static server str methodname()   {       str purchid=SysComputedColumn::returnField(dataentityviewstr(Dataentityname),d...