Showing posts with label Tips Tricks. Show all posts
Showing posts with label Tips Tricks. Show all posts

Friday, January 20, 2012

ROUND Function

ROUND function in NAV, rounds the value of a numeric variable.

For Example: ROUND(1234.56789, 0.001, ‘>’) returns 1,234.568

NewNumber := ROUND(Number [, Precision] [, Direction])

You can give your own precision in this function.


For Example: ROUND(1234.56789,0.50,’=’) returns 1234.50 i.e. nearest 50


ROUND(1234.4956789,0.25,'<') returns 1,234.25

Wednesday, February 16, 2011

How does Dynamics NAV validates the Credit Card number for Online Payments

Dynamics NAV 2009 R2 has a new feature called “Online Services” and using this functionality you can accept and process credit card payments in Microsoft Dynamics NAV.This online credit card payment feature automates authorizing credit card amounts at the time of the order and processing the actual charge when the order is shipped and invoiced.

In order to use this online payment services, you need to setup payment services, customer payment methods and credit cards for the customers. While setting up the Number field in the Credit Card page (Customer Card—>Customers—>Credit Cards), Dynamics NAV automatically validates value for the correct credit card number and gives the error message for invalid credit card numbers.

image

This validation is not a real credit card number validation from the service providers but uses the algorithm called “Modulus10”. This algorithm was designed to protect against accidental errors, not malicious attacks. Most credit cards and many government identification numbers use the algorithm as a simple method of distinguishing valid numbers from collections of random digits. You can find the related C/AL code in the codeunit 827 “DO Payment Card Validation” function “IsModulus10”.

Friday, December 24, 2010

Locking and Unlocking Objects– Auto-Lock on Design

In Microsoft Dynamics NAV 2009 R2, you can lock an object in Object Designer using Lock option. Along with Lock we have other options like Unlock and Force Unlock.

Along with these features you can automatically lock an object while opening the object in design mode.

This option is available in the Tools->Options->Auto-Lock on Design.

image

Even though you can lock objects, it is still possible for developers to have concurrency issues, as shown in the following examples.

  • A developer opens an object in the designer but does not lock it. The developer makes several changes to the object and saves the changes periodically. At the same time, a second developer locks the object, and the first developer cannot save design changes to the object. The first developer gets an error message that the object is locked by the second developer.
  • A developer locks an object. A second developer opens the locked object in read-only mode, and then the first developer unlocks the object. The second developer still cannot save design changes to the object even though the object is now unlocked because it is open in read-only mode.

System Indicator–Dynamics NAV 2009 R2

Till now all NAV users including developers or end users felt little difficult to identify the different instances of NAV. Now we have a solution called system indicator in NAV 2009 R2 release to differentiate different instances like production environment and test environment.

Once you setup the system indicator in the company information, you can see the indicator text in the top right side of each page in the Role Tailored Client…Cool…Winking smile

image

image

NOTE: Refer GetSystemIndicator function in the Codeunit 1 ApplicationManagement.

Monday, November 22, 2010

Why manually renaming a record takes little time?

In Dynamics NAV, if you try to modify the primary key field values it will take little time to change the value and also shows the window processing different tables.

When you try to change the primary key field value, internally it will check for the fields in all the tables which has the table relation to the primary key. That means system will check for the foreign keys related to the primary key and change the field value to the new value.

Pointing upLet’s say you have tables like sales header & sales line and if you want to reflect the primary key changes in the sales header to sales line, provide the table relations in the sales line.

rename

Wednesday, October 20, 2010

TEMPORARYPATH and APPLICATIONPATH Functions

TEMPORARYPATH: This function returns the path to the directory where the temporary file for Microsoft Dynamics NAV is stored.

This function returns the following path in the classic client:image

This function returns the following path In the RT client: image

APPLICATIONPATH:  This function returns the path to the directory where the executable file for Microsoft Dynamics NAV is installed.

This function return the following path in the classic client:image

This function return the following path in the RT client:image

Tuesday, September 21, 2010

CurrFieldNo

We all know that CurrFieldNo contains the field number of the current field in the current form.

Today I noticed that even though it contains the field number, by the time of executing table trigger (like OnModify or OnDelete), it contains zero (not the last modified field number).

Friday, July 23, 2010

IndentationColumnName and IndentationControls properties

IndentationColumnName and IndentationControls are the page properties in the NAV 2009. These properties are used to indent the controls or columns.

Transformation Tool will automatically convert the following type of code in the form and adjust the above two properties in the page to show the data as indented.

For Example: Form 18, CurrForm.Name.UPDATEINDENT := Indentation * 220;

Now the major problem in the pages is, you cannot use these properties for the fields that are editable and has a table relation.

For example, you cannot indent Item No. or Location Code in the Item Journal page because these fields are editable and has a relation with another table. If you try to indent these fields, while entering the data into these fields, field value is automatically updated with the first value.

If you press “1” in the Item No. field, it will be automatically filled with the first value starting with 1 like “1000”.

Friday, June 25, 2010

Dynamics NAV Testing Framework - Create Handler Functions

Microsoft Dynamics NAV 2009 SP1 includes the following features to help you test your application:

  • Test codeunits

  • Test runner codeunits

  • UI handlers

  • ASSERTERROR statement

Application Test Toolset provided by Microsoft includes the Test Runner and sample Test Codeunits.

To create automated tests, you must write code to handle all UI interactions so that the tests do not require user interaction when running. To do this, you create the following special handler functions:

  • MessageHandler: Handles MESSAGE statements.
  • ConfirmHandler: Handles CONFIRM statements.
  • StrMenuHandler: Handles STRMENU statements.
  • FormHandler: Handles specific forms or pages that are not run modally.
  • ModalFormHandler: Handles specific forms or pages that are run modally.
  • ReportHandler: Handles specific reports.

In the following post, I included sample UI Handler Functions which can be used while creating test codeunits.

Signature: MessageHandler <Function name>(<Msg> : Text[1024])

Sample Code:

    [MessageHandler]
    PROCEDURE MessageHandler@1100499002(Msg@1100499000 : Text[150]);
    VAR
      Text001@1100499001 : TextConst 'ENU=Sales Order posted sucessfully.';
    BEGIN
      IF Msg <> Text001 THEN
        ERROR('Unknown Message');
    END;

 

Signature: ConfirmHandler <Function name>(<Question> : Text[1024]; VAR <Reply> : Boolean)

Sample Code:

    [ConfirmHandler]
    PROCEDURE ConfirmDialogYes@1102601013(Question@1102601000 : Text[1024];VAR Reply@1102601001 : Boolean);
    VAR
      Text001@1100499001 : TextConst 'ENU=Do you want to post the Sales Order?';
    BEGIN
      IF Question <> Text001 THEN
        ERROR('Unknown Confirm Text; %1',Question);
      Reply := TRUE;
    END;

 

Signature: StrMenuHandler <Function name>(<Options : Test[1024]; VAR <Choice> : Integer; <Instruction> : Text[1024])

Sample Code:

    [StrMenuHandler]
    PROCEDURE StrMenuHandler@1100499000(Options@1100499000 : Text[100];VAR Choice@1100499001 : Integer;Instruction@1100499002 : Text[100]);
    VAR
      Text000@1100499003 : TextConst 'ENU=&Ship,&Invoice,Ship &and Invoice';
    BEGIN
      IF Options = Text000 THEN
        Choice := 1;
    END;

 

Signature: FormHandler <Function name>(VAR <form name> : Form <form id>)

Sample Code:

    [FormHandler]
    PROCEDURE FormHandler@1100499001(VAR FormName@1100499000 : Form 21);
    BEGIN
      FormName.ActivateFields
    END;

 

Signature: ModalFormHandler <Function name>(VAR <form name> : Form <form id>; VAR <Response> : Action)

Sample Code:

    [ModalFormHandler]
    PROCEDURE ModalFormHandler@1100499002(VAR FormName@1100499000 : Form 342;VAR ReplyAction@1100499001 : Action);
    BEGIN
      ReplyAction := ACTION::LookupOK;
    END;

NOTE: UI Handler functions should be specified in the main test function as below.

image

Wednesday, June 2, 2010

Shortcuts in NAV 2009 (Special for List Page)

In NAV 2009 SP1, we all know that Ctrl+Shift+V is to open the page in View Mode, Ctrl+Shift+E is to open the page in Edit Mode.

Along with the above two shortcuts, we also have Ctrl+Shift+L to open the list page in View Mode, Ctrl+Shift+K is to open the list page in Edit Mode.

image But the second shortcuts (Ctrl+Shift+L, Ctrl+Shift+K) won’t work for all list pages. My learning today is, second shortcuts are only applied to the list pages which does not have a card page attached to it.

For Example: Payment Terms page which has no card page linked will show Ctrl+Shift+L and Ctrl+Shift+K.

imageFor Example:  Item List page which has card page (30) linked will show Ctrl+Shift+V and Ctrl+Shift+E.

image

Monday, May 24, 2010

How to insert records into NAV from Visual Studio

Below is a simple console application to create a customer record from the visual studio.

namespace ConsoleApplication1
{
    using Customer;
    class Program
    {
        static void Main(string[] args)
        {
            Customer_Service service = new Customer_Service();
            service.UseDefaultCredentials = true;
            Customer.Customer customer = new Customer.Customer() { No = "123491", Blocked = Blocked.Ship};
            service.Create(ref customer);
        }   
    }
}

This will insert customer record but Blocked field does not contains the correct value. This can be achieved by changing the line as below:

Customer.Customer customer = new Customer.Customer() { No = "123491", Blocked = Blocked.Ship, BlockedSpecified = true};

This is mostly required for all fields except the string type because I think web services request/responses are in xml and type conversions are required internally from string to other data type.

Thursday, May 20, 2010

HideValue Property in NAV 2009 Pages

May be many of you are aware of the new field property “HideValue” for the Pages.

imageIf you set this property to TRUE, value in this field is not displayed in the Page. In the following scenario, I will explain how to automatically set this property to TRUE using the Transformation Tool, instead of changing the property value manually.

Let’s go to the customer card and go to OnFormat Trigger of the Name field. Adding one line of code will do the same functionality as HideValue property.

image Transform the form to page using the Transformation Tool and check the output in Role Tailored Client.

Form Output:image

Page Output:image

Monday, May 10, 2010

sp_$ndo$loginproc Login Stored Procedure on the SQL Server Option

A login stored procedure is a stored procedure that you can use to perform predefined functions after a user logs on to Microsoft Dynamics NAV with Microsoft SQL Server. A typical function would be to generate a message informing the user that the database is currently in single-user mode so that an administrator can perform database maintenance tasks and is therefore inaccessible.

The login stored procedure is run immediately after the user has logged on to SQL Server and opened a database and before Microsoft Dynamics NAV carries out any tasks including executing any C/AL triggers. The user must have successfully logged on to the server and have access to the database before the stored procedure is run.

Creating the Stored Procedure

The stored procedure is created in the database and has a predefined name and a list of parameters.

The stored procedure is called [sp_$ndo$loginproc] and has the following characteristics:

  • It takes two VARCHAR parameters: the name of the application and the C/SIDE version number. These parameters must be declared as part of the stored procedure but do not have to be used.

  • It can perform transactions. Microsoft Dynamics NAV uses a COMMIT to flush any outstanding transactions after the stored procedure has finished executing.

  • The RAISERROR statement can be used to display an error message in Microsoft Dynamics NAV and prevent the user from accessing the database.

  • The PRINT statement can be used to display a warning in Microsoft Dynamics NAV and allow the user to access the database.

  • If the stored procedure returns a value, it is ignored.

  • If the stored procedure does not exist, no action is taken by Microsoft Dynamics NAV and the login process continues as usual.

The following examples show how to create a login procedure in the Query Analyzer tool. The database must be selected before these statements are executed.

Example 1

The following code example displays a warning message in Microsoft Dynamics NAV and permits the login.

IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'sp_$ndo$loginproc' AND type = 'P')
DROP PROCEDURE [sp_$ndo$loginproc]
GO
CREATE PROCEDURE [sp_$ndo$loginproc]
@appname VARCHAR(64) = NULL,
@appversion VARCHAR(16) = NULL
AS
BEGIN
PRINT 'The system will be unavailable on Sunday April 1.'
END
GO
GRANT EXECUTE ON [sp_$ndo$loginproc] TO public
GO

Example 2

The following code example displays an error message in Microsoft Dynamics NAV and prevents the login.

IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'sp_$ndo$loginproc' AND type = 'P')
DROP PROCEDURE [sp_$ndo$loginproc]
GO
CREATE PROCEDURE [sp_$ndo$loginproc]
@appname VARCHAR(64) = NULL,
@appversion VARCHAR(16) = NULL
AS
BEGIN
IF SUSER_SNAME() IN ('ACCOUNTS\jim', 'SALES\bill')
RAISERROR ('Contact the system administrator.', 11, 1)
END
GO
GRANT EXECUTE ON [sp_$ndo$loginproc] TO public
GO

Sunday, April 18, 2010

DataCaptionFields and DataCaptionExpr property

This is a simple and known work around to set the form/page caption. This is particularly useful if you want to set an option field as form caption because changing the DataCaptionFields property won't work in the form and page.

In the following example scenario, I will include "Document Type" into the caption of the sales order form. This can be achieved by simply creating a function and changing the DataCaptionExpr property.

  • Create a function.

image

  • Add the following code in the function.

image

  • Change the DataCaptionExpr property as below:

image

  • Run the Sales Order and see the ouput.image

Tuesday, March 23, 2010

Wednesday, March 17, 2010

How to close the main form immediately after closing the sub form

Here is the standard NAV example to close the main form immediately after closing the sub form.

1) Open the Form 5784 from the Object Designer.

2) Click the Modify button to open the “Source Document Filter Card” from the ‘Filters to Get Source Docs.’ form.

3) Close the “Source Document Filter Card”. This will close the main form “Filters to Get Source Docs.” as well.

You can close the form conditionally, using the following set of example code in the ‘Run’ button.

GetSourceBatch.USEREQUESTFORM(ShowRequestForm);
GetSourceBatch.RUNMODAL;
IF GetSourceBatch.NotCancelled THEN
  CurrForm.CLOSE;

Friday, January 29, 2010

Calculated field on a page is only recalculated when the OnValidation trigger is run

A page will only update a field if it detects that there is some code on the OnValidate trigger. This is done for performance reasons to avoid unnecessary updates.

Please click the link to read the complete story from the Microsoft Dynamics NAV Team Blog.

Saturday, November 28, 2009

How to block New, Edit and View actions in the ListPage

In Microsoft Dynamics NAV RT Client, pages has default actions like New, Edit, View and etc…imageIn the ListPage, New action is promoted and shown in the New Promoted Category. This action is not promoted in the card part. 

image According to my requirement, I do not want New promoted action in the listpage. This can be achived by customizing the Actions like the following:

image image

But this process should need to be done in every client. The same requirement can be achieved by modifying the TIF information.

For Customer List Example: Remove the CardFormID field value in the TIF information for the Customer List and transform the page to form..

image image image

Limitations: Double clicking the Customer List will not open the Customer Card (Standard Functionality). Work around is to create a new action to open the Card and promote this action.

image

Friday, November 27, 2009

SAVERECORD and UPDATE

In Microsoft Dynamics NAV, CurrForm.SAVERECORD or CurrPage.SAVERECORD is used to save the current record shown on the form/page. CurrForm.UPDATE(True or False) or CurrPage.UPDATE(True or False) is used to save the current record based on the parameter and updates the controls in the form/page.

Using the two functions together in the form/page does not give any error normally but error will be displayed in pages if the following code is called before inserting the record.

CurrPage.SAVERECORD();//Which save the record.
CurrPage.UPDATE;//Which updates the controls.

For Example: Add the above lines of code in the Type – OnValidate() in the “46 Sales Order Subform” page and try to insert the sales line.

image This is because above set of code is trying to insert the record in two places one is using SAVERECORD and second is UPDATE (even though Parameter is FALSE).

Thursday, November 26, 2009

How to read BLOB data and export into a File

In Microsoft Dynamics NAV tables, we can create BLOB fields to store large amount of data. It is not possible to read the data in the BLOB fields directly.

The following steps shows the procedure to read the BLOB data. In this example, I have taken “User Metadata” table to read the data in the “Page Metadate Delta” field.

1) Create a codeunit with the below variables.

Name DataType Subtype Length
UserMetadata Record User Metadata  
Data InStream    
Line Text   1024
Pos Integer    
File1 File    

2) Add the following code to the codeunit.

image 3) Save and Run the codeunit. Text file will be created in the given path with the data in the BLOB field.

Thanks,

Veerendra CH.