Saturday, April 20, 2019

Report.SaveAsPDF in Business Central (Workaround) - Download Report PDF in Business Central

Hello Friends,

As we know, Report.SaveAsPDF or Report.SaveAsExcel not supported in Business Central Cloud (SaaS) version.

We have an alternate code for solution. We can save Report in Stream objects than after convert to file using Blob Export function.

Here is the sample code to download work order report in PDF file with Customize file Name.


pageextension 50212 SalesOrderEx extends "Sales Order"
{
    layout
    {
        // Add changes to page layout here
    }

    actions
    {
        // Add changes to page actions here
        addlast("&Print")
        {
            action("Download Report")
            {
                ApplicationArea = All;
                Image = ExportFile;
                trigger OnAction()
                var
                    TempBlob_lRec: Record TempBlob temporary;
                    Out: OutStream;
                    RecRef: RecordRef;
                    FileManagement_lCdu: Codeunit "File Management";
                    SalesHeader_lRec: Record "Sales Header";
                begin
                    TempBlob_lRec.Blob.CreateOutStream(Out, TEXTENCODING::UTF8);
                    SalesHeader_lRec.Reset;
                    SalesHeader_lRec.SetRange("Document Type", Rec."Document Type");
                    SalesHeader_lRec.SetRange("No.", Rec."No.");
                    SalesHeader_lRec.FindFirst();
                    RecRef.GetTable(SalesHeader_lRec);
                    REPORT.SAVEAS(752, '', REPORTFORMAT::Pdf, Out, RecRef);
                    FileManagement_lCdu.BLOBExport(TempBlob_lRec, STRSUBSTNO('SalesOrder_%1.Pdf', "No."), TRUE);
                end;

            }
        }
    }


Hope this help someone to get solution of download pdf file in business central

Thank you for Reading...

Keep Sharing...Keep Growing....

Sunday, March 17, 2019

Transaction No. Update in Ledger and Posted Transnational Tables in Dynamics NAV

Hello Friends,

When we create new G/L Entry manual in 17 G/L Entry table than most of time we forgot to set Transaction No. to max value + 1 in new inserted entry.

When system post any new G/L Entry, It has take transaction no.from last entry and increment by 1 to create new entry.

So, if result is that Transaction No. start duplicate values and it cause issue some reports and reverse transaction.

So, i have create batch process to correct unique incremental value in posted entries.

Identify the G/L Entry number from where the system start creating duplicate transaction number.

Now the following batch process correct data, 

Sample Code

//17
GL_lRec.RESET;
GL_lRec.SETRANGE("Posting Date","Posting Date");
GL_lRec.SETRANGE("Document No.","Document No.");
IF GL_lRec.FINDSET THEN BEGIN
  REPEAT
    IF GL_lRec."Transaction No." = OldTranscationNo_gInt  THEN BEGIN
      GL_lRec."Transaction No." := NewTranscationNo_gInt;
      GL_lRec.MODIFY;
    END;
  UNTIL GL_lRec.NEXT = 0;
END;

Download the batchjob object from attached link:
https://1drv.ms/u/s!An8nhANnLJmtkBgLpHo4bTcvA4pS

Let me know if you have any query
Thank you for reading

Keep Sharing..Keep Growing...

Merge Object Using Powershell (CU Update & NAV Upgrade)

Hello Friends,

Use the NAV Development Shell to auto merge the NAV Objects

It is very useful for

  • CU Upgrade
  • NAV Upgrade
  • Bug Fix Merge
  • Big/Small Functionality Merge
Suppose we take one example to install CU 17 to customer object having CU11

1) Create 4 Folder as shown in following snapshot.
















2) Open NAV Development Shell using administrator and following script

Cmdlet: Merge-NAVApplicationObject -OriginalPath C:\Users\nishit\Desktop\Temp\Shyam\1Original\*.txt -ModifiedPath  C:\Users\nishit\Desktop\Temp\Shyam\2Modified\*.txt -TargetPath C:\Users\nishit\Desktop\Temp\Shyam\3Target\*.txt -ResultPath C:\Users\nishit\Desktop\Temp\Shyam\4Result\
3) System auto merge targe file and show the result, You need to solve conflict files





































Done.

If you have query than write comments
Thank you for reading.

Keep Sharing..Keep Growing...

DataMatrix Code Print from Microsoft Dynamics NAV

Hello Friends,

Now you can easily generate DataMatrix Code (like QR Code) from Microsoft Dynamics NAV


Sample DataMatrix Output:




















Sample of Dynamics NAV Code

      FileNameBmp := FileManagement.ServerTempFileName('bmp');
      DataMatrix := DataMatrix.DmtxImageEncoder;
      Image := DataMatrix.EncodeImage(Text2Encode);
      Bitmap := Bitmap.Bitmap(Image, pxWidth, pxHeight);
      Bitmap.Save(FileNameBmp);

      CLEAR(TempBlob);
      IF TempBlob.INSERT THEN;
      FileManagement.BLOBImportFromServerFile(TempBlob, FileNameBmp);
      TempBlob.MODIFY;


Copy DLL File in Add-ins Folder
















Download the sample object from attached link
https://1drv.ms/u/s!An8nhANnLJmtkBaBKCwFT_VX00NR

Write the comments if need more detail
Thank you for reading.
Keep Sharing...Keep Growing.

Modify Field value using RecordRef & FieldRef

Hello Friends,

You can modify any table field value using RecordRef and FieldRef

A RecordRef object references a record in a table. Typically, you use a RecordRef object in functions that must apply to more than one table, not to a specific table. For example, you could use a RecordRef object in a function that loops through several tables or as a parameter of a function that is called for records of different tables.
The RecordRef object can refer to any table in the database. Use the OPEN Function (RecordRef) to use the table number to select the table that you want to access, or use the GETTABLE Function (RecordRef) to use another record variable to select the table that you want to access.
If one RecordRef variable is assigned to another RecordRef variable, then they both refer to the same table instance.
Example of code to modify field value using record ref & field ref variable
********** Sample Code to Modify Record using Record Reference and Modify the field value using Field Ref *************************

IF STRPOS(FORMAT(ApprovalEntry."Record ID to Approve"),'Gen. Journal Line') <> 0 THEN BEGIN
  RecRef_lRecRef.GET(ApprovalEntry."Record ID to Approve");
  FieldRef_lFrf := RecRef_lRecRef.FIELD(50084);
  FieldRef_lFrf.VALUE(TRUE);
  RecRef_lRecRef.MODIFY;
  RecRef_lRecRef.CLOSE;
END;

// ApprovalEntry."Record ID to Approve" à Record ID field and contain value like ('Gen. Journal Line :Default,Default,10000')

Name
DataType
Subtype
Length
RecRef_lRecRef  
RecordRef  

FieldRef_lFrf       
FieldRef     


Saturday, October 27, 2018

Dynamics 365 Business Central: handling breaking schema changes on production

Hello Friends,
I saw many requests on forums in the last days related to one of the most noisy topic when working with Extensions in Dynamics 365 Business Central (SaaS version): how to handle breaking schema changes.
The tipical scenario is the following:
  1. You create an extension (version 1.0) that contains a custom table with some fields and some keys and publish it. All is ok.
  2. Then, you create a new version of the same extension (2.0) where you change some field data types (or some field properties) or you change some table’s keys.
  3. You publish the new 2.0 version and…
ERROR: “Unsupported table change” message or (for keys) the message is something like “An unsupported key change was detected. Keys cannot be changed, removed, or reordered. New keys can only be added to the end of the list“.
Previously (in the C/AL era) if you change a field property on a table or if you change a table’s key and you’re sure that this will not occour in a data loss, you could export the fob and import them in the production environment using the force option and all works.
Now in the cloud environment things are different.
Extensions V2 do not support breaking schema changes across synchronized versions of the extension. Uninstalling and unpublishing the 1.0 extension will not remove the schema elements coming from an extension.
In your local sandbox environment you can “clean” your environment in the following ways:
  • From Visual Studio Code by using “schemaUpdateMode”: “Recreate” in launch.json
  • From Powershell by executing the following command:
Sync-NavApp -Name <name of extension> -Version <Version of extension> -Tenant <Tenant name> -Mode Clean
This will remove all the schema elements across all versions of the extension (and also all the data). The next time you will deploy your extension, the system will not found an “old schema” to compare agains the new schema and all your changes will be considered as new.
What about in the production environment?
In a production environment, once an extension is synchronized to a tenant then all the next versions (upgrades) must have a schema that is backward compatible. To handle this scenario (that can occour, I agree…) you can:
  1. Mark the changed field with ObsoleteState = Pending or Removed.
  2. Create a new table (or new fields or keys) with the new data type or values.
  3. Create an Upgrade codeunit that moves the old data to the new data.
  4. Use the new field or keys.
Obsolete_01.jpg
The ObsoleteState can have these values:
  • Pending: the element will be obsolete in a future release. This setting has no effect on the current use of the table, field, or key in code.
  • Obsolete or Removed: the element is not deleted from the database; however, references to the the element in code are only allowed in upgrade codeunits. References from other objects will result in a runtime error.
If you need to change a primary key of a table from a previously deployed 1.0 extension, I think the best way is to create a new table and mark the old table as obsolete. In your Upgrade codeunit, move the data from the old table to the new table.
Obsolete_02.jpg
Lesson learned after this post? That in the SaaS era, you have to deploy in a production environment more and more carefully than before and only when your design is really ready!

Sunday, October 21, 2018

Field can appear only once in table Dynamics 365 Business Central

Hello Friends,

If you try to add new field using table extension and field already exists in standard table by other installed extension or manual created in standard table using developer environment (on-prime). 

tableextension 50001 CustomreExt extends Customer
{
fields
{
field(50000; "Field From BC"; Integer)
{
DataClassification = ToBeClassified;
}
}

var
myInt: Integer;
}

When you publish than extension than system give error failed with code 422. Reason:
The field ID '50000' can only appear once in the table 'Customer'

In this case we already created field using development environment (on-prime D365 BC)

Error
Error coming at publishing of extension,



















Thank you for reading...
Write a comment if you have any concern.

Saturday, October 20, 2018

Publish One More D365 Business Central Extension in App Source - Product Catalogue

Hello Friends,

Me and my team at Intech-Systems, Publish one more extension in App Source for Dynamics 365 Business Central,

It was very good experience to working with App Source Team for multiple email conversion and correction in app to qualifying it for publish on app source.

Product Catalogue

Intech Systems Pvt Ltd.


Click here to view it on app source - App Source Link

Product Catalogue App provides an easily way to configure the Items on the Sales Document.
In a business system, every item is defined with a unique code so there wouldn't be any conflict between the items. While creating a Sales Quote or a Sales Order document, you will need to enter the Item Code in Sales Line. If yours is a small business, you might remember every item code in detail but if yours is a big company with many products, it is difficult to remember all the codes. In this situation, you will have to open the item codes' list and search for the required Item Code.
Product Catalogue App helps you solve the above issue. With this App, you don't have to remember all the item codes. You have to categorise the Items into the following three categories.
  • Product: Product is the first main group to add Main Product details.
  • Category: Category is the second group to add the sub details of Product.
  • Model: Model is the third group to add the sub details of the Category Group.
Features:
  • Easily Manage the Items based on the Product, Category and Model No. wise.
  • Provides an easy way to assign Items on Sales Quote and Sales Order.
  • Configure the Suggested Items for specific Items.
Benefits:
  • User can easily filter and search the Items based on the Product, Category and Model wise.
  • In big organization, it is easily to review Item based on Product, Category and Model wise.
  • While assigning Items on Sales Quote and Sales Document, we can easily identify and select Items based on the Product, Category and Model wise.
  • It reduces the time and increase the efficiency for Sales Document Transactions.
Try this app now for less complexity, more automation and seamless process. No hassle of remembering codes or keeping a track of all the codes, thus increasing productivity.
This extension supports both the Essential and Premium edition of Microsoft Dynamics 365 Business Central. This extension is available in the United States.

Table Trigger available with extended table and sequence of execution

Hello Friends,

With new version of AL Code, Now the table base trigger available with extended tables and we can use it as normal table trigger.

The tableextension object has four new triggers:
  • OnInsert
  • OnModify
  • OnDelete
  • OnRename




















What are these triggers and how are they related to the OnInsert / etc. triggers in the base table? And what’s the difference with the already existing OnBefore and OnAfter triggers in the tableextension object?
The difference is that these new triggers will be executed before the data of the table has been written to the database. While the OnAfter triggers will be executed after the data has been written to the database.
Table extension trigger execute before the table trigger.
With so many triggers and events, I thought it would be a good idea to compose a list with the correct order in which they are executed. So here is a table for the database insert (same applies to modify, delete and rename of course):

Thank you reading,
Let write in comments if you want to know more detail.

Thursday, October 18, 2018

Develop First VS Code Extension with D365 Business Central On-Prime Version

Hello Friends,

Let jump into future of development with VS Code,

This blog will help you to configure your first AL Language extension with D365 Business Central On-Prime Server.

Step 1 - Download and install D365 Business Central On-Prime Version.
             You can download from this link
           

Step 2 - Download and install VS Code from link - https://code.visualstudio.com/download
              After that, install latest AL Language extension in VS Code.
           

Step 3 - Make sure that you are able to run web client of D365 BC on-prime version and base URL setup correctly in configuration file.

D365 BC On-Prime Database and Server Instance Detail
















Business Central Web client working properly.






















Configure "Web Client Base URL" (PublicWebBaseUrl) in service to avoid error during publish vs code extension (Could not open the specified startup page. Please check that the server configuration key PublicWebBaseUrl has been properly set)























Step 4 - Start the VS Code and go to command plate to create new projects,
              Write AL!GO on command plate to create new project.


























Go to command palette from View >> Command Pallet (short cut key - Ctrl + Shift + P or F1)






















write AL:Go!  to create new AL Language extension project
















Write the name of project at end.















Step 5 - System will default create the app.json and launch.json files, configure your op-prime business central service in lanuch.json file as shown in following snapshot.

Default files create with new project


app.json file contain the detail about id, app name and object range details.



launch.json contain the detail about configure business central service detail to start your project with link service while pressing F5 / Ctrl + F5 and also require to download symbols.


















Step 6 - Download the base business central object (symbols) from link server in launch.json file.
              Go to command plate and write AL!Download Symbols
















After successfully download symbols, system will show following message.




















Step 7 - Now the all setup completed and we are ready publish our first Hello World ! extension in on-prime D365 Business Central.

Press F5 publish your first extension on link server.


















Very useful AL Command keyboard shortcut to remember for developer

Keyboard Shortcut Action
Ctrl+Shift+P Show All Commands
Ctrl+F7 Download source code
Alt+A Alt+L Go! Generates a HelloWorld project
Ctrl+Shift+B Package
F5 Publish
Ctrl+F5 Publish without debugging
F6 Publish and open the designer
Ctrl+F2 Update the compiler used by the service tier(s)

==========================================================
Tips - Step the "NetFx40_LegacySecurityPolicy" parameter to false in "Microsoft.Dynamics.Nav.Server.exe.config" file to avoid error in publish extension from VS Code.

You can find config file from path.


















Set enabled = false in setting and restart the service to take effect.




























I hope this blog help someone to setup there first extension development

If you need any help than write in comments.

Thank you for reading.
Keep Sharing...Keep Growing...