Friday, 4 December 2020

Open the Journal lines form in D365FO with Jumpref

 Requirement: To open Journal lines form by clicking on view details of the filed on the form.


Development:

1. RegisterOverride the jump ref method on a form

[ExtensionOf(formStr(ProjInvoiceProposalDetail))]

final class ProjInvoiceProposalDetailFormBKA_Extension

{

    public void init()

    {

        next init();


        //ProjProposalCost_BKATrackingID is control name on form

        ProjProposalCost_BKATrackingID.registerOverrideMethod(

                methodStr(FormStringControl, jumpRef),

                methodStr(ProjInvoiceProposalDetailFormBKA_Extension, bkaTrackingIdJumpRef),

                this);

    }


    private void akaTrackingIdJumpRef(FormStringControl _formStringControl)

    {

        VendInvoiceJour::BKATrackingIDJumpRef(ProjProposalCost.BKATrackingId);

        _formStringControl.jumpRef();

    }

}


//I have centralized the jumpref's method on a table

//Opening the journal lines form is bit tricky, so below is the code will work

[ExtensionOf(tableStr(VendInvoiceJour))]

final class VendInvoiceJourBKA_Extension

{

 static void BKATrackingIDJumpRef(BKATrackingID _trackingId)

    {

        Args                        args, transArgs;

        FormRun                     formRun, transFormRun;

        JournalFormTable            journalForm;

        LedgerJournalTrans          ledgerJournalTrans;

        LedgerJournalTable          ledgerJournaltable;

        MenuFunction                menuFunction;

        ;

        


        changecompany (_trackingIdCompany)

        {

            //todo: change code for tracking Id

            select firstonly ledgerJournalTrans

               where ledgerJournalTrans.Voucher == _trackingId;


            ledgerJournaltable = LedgerJournalTable::find(ledgerJournaltrans.JournalNum);

        }


        //Open form

        args = new Args();

        args.name(formStr(LedgerJournalTable));

        args.record(ledgerJournaltable);


        formRun = classfactory.formRunClass(args);

        formRun.init();

        LedgerJournalFormTable journalFormTable = formRun.journalForm();

        journalFormTable.journalTableData(JournalTableData::newTable(ledgerJournalTable));


        transArgs = new Args();

        transArgs.caller(formRun);


        if (ledgerJournaltable.JournalType == LedgerJournalType::Daily)

        {

            transArgs.name(formStr(LedgerJournalTransDaily));

        }

        else if (ledgerJournaltable.JournalType == LedgerJournalType::VendInvoiceRegister)

        {

            transArgs.name(formStr(LedgerJournalTransVendInvoice));

        }

        transArgs.record(ledgerJournaltable);


        transFormRun  = classfactory.formRunClass(transArgs);

        transFormRun.init();

        transFormRun.run();

}

}

Monday, 5 October 2020

Debug a copy of the production database

Sometimes when working, you might need to connect to a managed environment (like UAT) to debug if it is throwing some errors when running your functional process, where the same data may  not be available in your development (Cloud hosted) environment. So, this post will help you to connect the cloud DB of managed environment from your cloud hosted environment.

 

Why we need to connect?

Suppose you are working on any managed services project or support project, based on SLA you might need to provide interim or solution ASAP, may be in few hours.

Now, refreshing the database for your development environment may take time, also there could be some approvals to refresh your development environment, which results in delay in providing the resolution if we like to use the same development environment. In that case we connect to database of the managed environment (UAT) and source code is from Cloud hosted (development) environment.

 

How to connect?

If we remember in AX2012 to connect to different instances, we connect to different configuration files. Here also the same, we create a new config file and we will configure and will connect it.

 

Where can we find config file?

Of course, every machine will have the default config file, where the file contains information of database and server. Check below path for web config file

K:\AosService\WebRoot

 


 

Procedure:

1.      Add your IP to safe list:

By default, all Sandbox Standard Acceptance Test environments use Microsoft Azure SQL Database as their database platform. The databases for these environments are protected by firewalls that restrict access to the Application Object Server (AOS) with which it was originally deployed.

A.     You need to add your IP to the enable list to log into Prod copy and open SSMS and write SQL script to add to safe list

Maintain > Enable access




B.     After logged into the prod copy environment open SSMS,

Get the server name, database name, user and password details from LCS project under Database accounts.






Login,

Server: ‘ServerName’.database.windows.net

Username: axdbadmin

Password: ‘password of axdbadmin from LCS’



Connection Properties,

Connect to database: ‘Database name from LCS’



After connecting to database from above procedure, write the below SQL script

 

EXECUTE sp_set_database_firewall_rule N'Debugging rule for DevTest environment', 'a.b.c.d', 'a.b.c.d';

 

Note: a.b.c.d is the IP address of your dev environment. Actually, it is the range else you can provide single IP.


C.     After executing the above command, log into Dev environment and open SSMS, check whether you have access to database 

 

Login,

Server: ‘ServerName’.database.windows.net

Username: axdbadmin

Password: ‘password of axdbadmin from LCS’


Connection Properties,

                  Connect to database: ‘Database name from LCS’




D.     Now, you are able to connect to UAT database in SSMS of DEV. In order to connect the D365FO application to UAT database, we need to create or modify the config file in Webroot.

 

Duplicate web config file and name it to web_UAT



Now open the web_UAT file in notepad and update the following

Database, DbServer, SqlPwd, SQLUser


E.     Now the config file is ready, in order to connect to UAT DB stop WWW (world wide web) service and rename the web file to web_Orig and web_UAT to web, start the WWW service. Now your F&O application connected to UAT database.




F.     In order to debug the UAT data, attach the process in debug in VS.

 

G.     To connect back to dev database, stop WWW service and change the web config file to web_UAT and web_Orig to web. Start the WWW service.


Reference:  https://docs.microsoft.com/en-us/dynamics365/fin-ops-core/dev-itpro/database/dbmovement-scenario-debugdiag

Friday, 18 September 2020

 Hyperlink on Field for SSRS report in D365FO

My requirement is to open a report on sales order or a transfer order depends on the caller.

After running the report it should open the sales order based on SalesId


Change the below properties
1. Color
2. Textbox properties > Action >Go to URl > select URL
    Write the below code in expression
    =Microsoft.Dynamics.Framework.Reports.BuiltInMethods.GenerateDrillThroughLink(Parameters!AX_ReportContext.Value, Parameters!AX_UserContext.Value, "SalesTable", "Display", "SalesTable", "SalesId", First(Fields!AGCReference.Value, "PalletLabelsPrintTmp"))


Format:
3
=Microsoft.Dynamics.Framework.Reports.BuiltInMethods.GenerateDrillThroughLink(
    Parameters!AX_ReportContext.Value, Parameters!AX_UserContext.Value,
    "[MenuItemName]", "[MenuItemType]", "[TableName]", "[FieldName"], "Field value")


Monday, 4 May 2020

Some useful lnfo of D365FO (How to open table browser, Models, Descriptor file)


1. To open the following in browser:
Table Browser
https://-----------.cloudax.dynamics.com/?mi=SysTableBrowser&prt=initial&limitednav=true&TableName=VendReceiptsListJour&cmp=USMF

Action MenuItem
https://---------.cloudax.dynamics.com/?cmp=WLF&mi=action:WHSWorkExecute&limitednav=true

Runnable class
https://--------.cloudax.dynamics.com/?cmp=USMF&mi=SysClassRunner&cls=classname



2. Powershell cmds to Import/Export/delete model in D365FO:
Export
cd K:\AosService\PackagesLocalDirectory\Bin

.\ModelUtil.exe -export -metadatastorepath=K:\AosService\PackagesLocalDirectory -modelname="CustomWithReport" -outputpath=C:\Temp

Import
cd K:\AosService\PackagesLocalDirectory\Bin

.\ModelUtil.exe -import -metadatastorepath=K:\AOSService\PackagesLocalDirectory -file=J:\CustomWithReport.axmodel

Delete
.\ModelUtil.exe -delete -metadatastorepath=K:\AOSService\PackagesLocalDirectory -modelname="CustomWithReport"

else you can delete the model directly by deleting the folder from K:\AosService\PackagesLocalDirectory. Before that stop World wide web service(It will stop AOS), Microsoft Batch service.
After delete restart service, refresh model in visual studio Dynamics 365-> update models-> refresh models and synchronize.

3. To add the model descriptor file to TFS
  1. In Visual Studio, in Team Explorer, open Source Control Explorer, and then right-click on the metadata folder (for example, \Trunk\Main\Metadata).
  2. In the Source Control Explorer toolbar, click Add Item to Folder.
  3. Select your model descriptor file. The model descriptor file is the XML file manifest of your model. It's located in the Descriptor folder of the package that the model belongs to.(K:\AosService\PackagesLocalDirectory\ModelName\Descriptor).

Monday, 20 April 2020

Flight features in D365FO

Flights are used to disable new features which will change the user experience. With this concept we are able to explicitly enable new features and not by default.

Scenario:

With the PU 34 update, MS introduced fights to Journal printing. So the new code is called as flight is disabled by default.

As the flight is not enabled, it will go to else part in the code shown in pic.

To enable flight to it, write the below script:

SQL:

INSERT INTO SYSFLIGHTING (FLIGHTNAME, ENABLED, FLIGHTSERVICEID) VALUES ('LedgerJournal_UseOldLegerJournalDPReport', 1, 12719367)

or

X++ :

if (!SysTestFlightingManager::isFlightEnabled("LedgerJournal_UseOldLegerJournalDPReport"))
        {
            SysTestFlightingManager::setFlightEnabled("LedgerJournal_UseOldLegerJournalDPReport", DefaultNoYes::Yes);
            Info("Flight enabled");
        }


Reference:

Thursday, 2 April 2020

X++ code to find the available printers to print from AX (Print Sales picking list report at designated printer)



printJobSettings  printJobSettings;
sysPrintOptions  sysPrintOptions;
map                     printerMap;
mapIterator         mapIterator;
    ;
printJobSettings = SysPrintOptions::newPrintJobSettingsOnServer();
sysPrintOptions = new sysPrintOptions();
sysPrintOptions.setPrintJobSettings(printJobSettings);
sysPrintOptions.buildPrinterMap();
printerMap        = sysPrintOptions.getPrinterMap();
mapIterator       = new mapIterator(printerMap);
mapIterator.begin();
while (mapIterator.more())
{
      info(mapIterator.value());
      mapIterator.next();
 }

Scenario:
In order to print a sales picking list to the desired destination(printer):

1. Class responsible to print picking list is "SalesPickingListJournalPrint".
2. You need to override the printSettings and pass it to FormLetter. Write the below code before call the doPrint method (SalesPickingListJournalPrint.doPrint())


private void ChangePrintSettings(Name_printerName)

{
    SRSPrintDestinationSettings printSettings = new SRSPrintDestinationSettings();

    printSettings.printMediumType(SRSPrintMediumType::Printer);
    printSettings.printerName(_printerName);

    //this.parmUsePrintManagement(false);
    this.parmPrinterSettingsFormLetter(printSettings.pack());