How to add user permission for Add-on specific objects

If you have created a new Add-on objects and now you need to execute these objects in the customer environment(Ex. Page 12103540, Page 12103560).
So, these object id's which are not a part of Dynamics NAV needs a permission to execute or modify or insert in some other workstations.

So, here is the sample code, permissions in the below code are assigned to TableData(you can change it to page or any other object based on your requirement).

Global variables.
Name                            DataType      Subtype            Length
UserRole                          Record Permission Set
Permission                       Record Permission
AllObj                             Record AllObj
User                               Record User
WindowsLogin                  Record User
WindowsAccessControl Record     Access Control

1. Assign the new user Role ID and User Role Name
2. If not user role inserted then sort the record based on object and object id's.
3. Fetch the Permission Role ID(insert,modify,delete,execute) from permission set table and assign it to permission table for the object id's which you need to assign permission.

Example:

UserRole."Role ID" := 'Addon1';
UserRole.Name := 'Required for all user';
IF NOT UserRole.INSERT THEN ;
AllObj.RESET;
AllObj.SETRANGE("Object Type",AllObj."Object Type"::TableData);
AllObj.SETFILTER(
  "Object ID",
  '12103560..12103580');
IF AllObj.FIND('-') THEN
  REPEAT
    Permission."Role ID" := UserRole."Role ID";
    Permission."Object Type" := AllObj."Object Type";
    Permission."Object ID" := AllObj."Object ID";

    Permission."Read Permission" := Permission."Read Permission"::Yes;
    IF AllObj."Object ID" IN [12103540, 12103560] THEN BEGIN
      Permission."Insert Permission" := Permission."Insert Permission"::Yes;
      Permission."Modify Permission" := Permission."Modify Permission"::Yes;
      Permission."Delete Permission" := Permission."Delete Permission"::Yes;
      Permission."Execute Permission" := Permission."Execute Permission"::Yes;
    END ELSE BEGIN
      Permission."Insert Permission" := Permission."Insert Permission"::" ";
      Permission."Modify Permission" := Permission."Modify Permission"::" ";
      Permission."Delete Permission" := Permission."Delete Permission"::" ";
      Permission."Execute Permission" := Permission."Execute Permission"::" ";
    END;
    IF NOT Permission.INSERT THEN ;
  UNTIL AllObj.NEXT = 0;


How to use code coverage tool (How it differs from debugger)

Code coverage is one of the interesting topic while testing and debugging. It is very useful when you want to test your work.

I can start this explanation with a very good example.

Suppose you have a sound recorder in your mobile, you will go to the app folder, you will open the sound recorder, start the sound recorder, hum a tune and will record it for some time. Once you are done with humming a tune/song. You will stop recording and start listening to the tune/song which you've recorded.

Well, Exactly in the same way even code coverage tool works.
Firstly to open a code coverage tool in RTC(Role Tailored Client) Go to the following path in RTC.

If you are on Company Cronus USA,
Then in the menusuite go to,
  • CRONUS USA, Inc./Departments/Administration/Application Tools/
  • Click on Code Coverage in application tools. 
  • Click on Start button.


Now continue with your actions which you are supposed to do on RTC.
Example: I clicked on release sales order and did some processing of some random action.

Now, when you come back to code coverage and click stop.

It displays where all the flow passed through internally when you clicked on action button. You can just have a quick look at the flow of actions during your test activity.


So where all you see the Coverage% as 100. At those places the code as been hit internally when you clicked on particular action button. However, you cant see the values here directly. This gives a quick flow of code but doesn't give data i.e updating. If you need to know the complete flow internally along with values updating internally then you need to go with Debugger in NAV.

Click on Tools in NAV IDE -> Debugger -> Debug Session
Assign a break point in a code and start debugging each and every lines of code. 

Hope this helps for many beginners :)

Concept of Job Queues (Lets go through the path of NAS Service in Dynamics NAV)

Job Queue enables to request, control the processing of report and execution of codeunit.
In job queue entries window, we enter the request for execution of report/codeunit. 

Once the job queue execution of codeunit/report is done it will update its status of success/failure in Job queue log entries.


In NAV 2015, 2016 Job Queue can be activated in 2 ways.

1. Manually with credentials of Server instance.  
2. through NAS server with credentials of user.


Job queue uses NAS to run objects automatically. 

So, before understanding job queue we need to know what is NAS, why we need NAS.

In this blog I will be discussing particulary the concept of NAS and how to configure it in various versions of NAV.

What is NAS ?
NAS service is a middle-tier server component that executes the business logic without user interaction. 
In NAV it supports application like microsoft office outlook integration and NAV job queue.  

Why we need NAS?
  • Efficiency and convenience - Create a separate instance for each NAS Service so that it doesn't interrupt other services. 
  • Performance - Configuring NAS to separate instance makes better use of server computer. It allows us to run more application with less degradation.
  • Efficient error tracking - If the NAS service terminates then it can be handled like any other windows service by configuring the recovery tab on server configuration tool in control panel to manage service. 

Configuring NAS server in NAV 2009, 2013 is different from configuring in NAV 2013 R2, 2015, 2016.

Earlier all the services were separate but now we can see the services like Client, SOAP. ODATA, NAS, Management services all in one single administration tool. This makes a way by running one instance it will make run many services.


So as versions of NAV got changed configuring NAS service also became easy.

1.     Configuring NAS in NAV 2009 and 2013.

To do this you should have Application server manager for microsoft dynamics nav. 

Go to start, search for Application server manager for microsoft dynamics nav.
If you don't find any, 

Then go to your DVD installer of NAV run the setup file.
Select Add or remove components as shown below.


Select Application server and choose run from my computer in the drop down.

Once done, click next and wait until installation is successful.
Now you have Application server installed in your machine.
Go to your local services by searching in start button for services or by just clicking in Run prompt for services.msc. You will see the service installed as shown below.
Logon with your domain account instead of Network service.
Right click on below mentioned server, properties – Logon - > enter your system login id and password.



Now in your start menu, open Application server manager for Microsoft Dynamics NAV.
Right click on application server – select new application server.

Provide the host name – local host
Service name – BHEESHMA-SQL (the name which is displayed in the above marked service.

A new node will be created. Just click on this node and enter details of the server you are using, the database name and company.
To setup job queue the parameter should be JOBQUEUE as described below.


Click on Start the service.
You can check for the active sessions that are running in your machine by running the system table active sessions.
In your NAV development environment go to Database information and select current sessions.
There you must be able to see the new sessions configured as shown in below fig.



Once you verify that NAS service is running start configuring a job queue.


How Job queue works in NAV 2015. 

I explained how to do setup in NAv 2009. In NAV 2015 its pretty easy jus go to your server instance and go to NAS services and give the codeunit and starting method you need to run.

1. To schedule a job queue in NAV 2015 same applies in NAV 2009 R2. In your RTC client, go to Job queue entries click on new.
Choose the report or the codeunit you need to run.


I've given No. of minutes between run as 1 which means for every one minute the report will be run automatically without user interface between the start and end time.

In the above example I've took General Journal - Test report. I have filled the data as shown in above fig. 

Now click on Set status to ready so that now it is ready for job queue. 

2. To run a job queue, go to Job queue card and in NAS Settings, specify  NAS computer  your are using and NAS instance. 
once its done click on start job queue. 

you will get the following warning message.

Start the NAS service.
Once you are done with above steps. The NAS server will internally run the codeunit or the report you mentioned automatically from the specified time.

If it has to be repeated everyday at some specified time. Then mention the date and time it should run in Job Queue Entries page and go to Recurrence fast tab and then select the day and time the codeunit/report should run automatically.




An Overview of Journal Template, Journal Batch and Journal Line

Journal Template :
They provide Journal structure and default information for journal batches.

Journal Templates are located in Journal Template page.


Definiton of Journal Template contains a series of attributes such as,


1. Name

2. Description
3. Type
4. Recurring
5. No. Series

Journal Template has relevant attributes that define nature and behavior of journal templates,


Journal Template Table field: Defines the Description of Journal


Test Report ID: Simulate the posting process

ex: General Journal as the associated test report named General Journal - Test

Posting Report ID: This report is printed when the user selects post and print.


Page ID: Some journal may require UI objects.

Ex. General Journals which have a special page for bank and cash.

Source code: Here you can enter trail code for all posting documents which are done through this  journal.


RecurringWhenever you post lines from a recurring journal, new lines are automatically created with a posting date defined in the recurring date formula.


Each journal template defines a default value of those attributes. The values that are defined in a template will be inherited by the journal batches which will be further inherited by journal Line.


Journal Batch: Journal batches usually serve to lines created by 2 different users called group journal lines.


They're created with the help of journal templates.



A journal batch is typically used to make a distinction between collections of logically grouped journal lines. A typical design is to have a journal batch for each user who enters lines. The batches are used during the posting process, in order to post one or multiple lines at once.

As shown in fig. The batch we have used is CASH for posting process to post that particulat line.



Journal Lines: Journal line will temporarily hold the transaction data until it is posted.

Until posting, Journal lines will be in draft state, means you can do correction/deletion o data.
Once the entry is posted line entries in journal are converted to Ledger Entries.





Journal lines contain the actual business data (posting dates, account numbers, amounts) that will be posted as ledger entries.

During posting, only the information from the journal lines is needed. However, the information has been created with the help of the journal templates and grouped together using the journal batches.
Posting creates ledger entries from the temporary content that is stored in the journal lines. Ledger entries are not created directly. Instead, they are posted from journal lines.
reference from community of dynamics.


In this, journal templates and batch is used if we need to create and post one or more entries. So, they're implemented in multiple areas of application like sales, purchases, cash receipts, payments, fixed assets.


Aggregation


There is a 1:n aggregation relationship between journal templates and journal batches, as well as between journal batches and journal lines. Deleting a template will cascade deletion of the related batches and lines. Deleting a batch will cascade into deletion of related lines.

Recurring Journals

A recurring journal is used to post transactions that repeat periodically. In a recurring journal, the user enters only the variable data, such as posting date, amounts, and accounts to be used for posting.
After posting a recurring journal, new journal lines are created containing the posting date for the next recurring period. The posting date recurrence pattern is previously defined in the Recurring Frequency field (for example, monthly recurrences(salary of an employee) are defined with the date formula 1M).
A boolean field named Recurring is placed on both the journal templates and journal batches, giving the possibility of defining the type of the journal to be used.

Standard Guidelines respected to navigation:



To keep a consistent user interface experience, it is recommended that the the following guidelines are taken respected concerning navigation:
  • Journal template to journal batches:
  • On the Journal Templates page, create an action called "Batches" and place it in the Navigate tab of the ribbon. Link the action to the batches list page.


fig shows batch action created and as been linked to batches list page. 

  • Journal batch to journal lines:
  • On the Batch page, create an action called "Edit Journal" in the Home ribbon tab.Link the action to the journal lines list page.




The action as been linked to journal lines through code.

In EditJournal - OnAction() trigger

GenJnlManagement.TemplateSelectionFromBatch(Rec);

Go to definiton of TemplateSelectionFromBatch(Rec) function and there you can see General journal lines as been called through code as shown below.



To keep a consistent user interface experience, it is recommended that the the following guidelines are taken respected concerning posting:
  • Posting multiple batches
  • On the Journal Batches page, posting actions (Post, Post and Print) are available. When invoked, the batch posting will iterate through all related journal lines and trigger the posting routine for all of the lines.



General Journals

The General Journal Templates page (101) uses the Gen. Journal Template table (80).
Various template types are defined: General,Sales,Purchases,Cash Receipts,Payments,Assets,Intercompany,Jobs. Based on the journal type, two other attributes are automatically set on the template lines as follows:
  • Page ID: Defines which journal page relates to the current journal template
  • Source Code: Filled with the default codes that are defined in Source Code Setup table (242).
The General Journals Batches page (251) is linked to the Gen. Journal Batch source table (232), which has a multiple-to-1 relationship with Gen. Journal Template table, based on the Journal Template Name field.
Some of the fields in the Gen. Journal Batch table are not editable. Instead, their value is automatically calculated from the parent Gen. Journal Template table. For example, the Recurring field (22) is a FlowField with the following calculation formula:
Lookup("Gen. Journal Template".Recurring WHERE (Name=FIELD(Journal Template Name)))
Similarly, the Template Type field is a FlowField that gets its value from the parent table:
Lookup("Gen. Journal Template".Type WHERE (Name=FIELD(Journal Template Name)))

Setting up a New Batch

When the user creates a new batch, the following field values are transferred from the Gen. Journal Template table to the Gen. Journal Batch table:
"Bal. Account Type" := GenJnlTemplate."Bal. Account Type";
"Bal. Account No." := GenJnlTemplate."Bal. Account No.";
"No. Series" := GenJnlTemplate."No. Series";
"Posting No. Series" := GenJnlTemplate."Posting No. Series";
"Reason Code" := GenJnlTemplate."Reason Code";
"Copy VAT Setup to Jnl. Lines" := GenJnlTemplate."Copy VAT Setup to Jnl. Lines";
"Allow VAT Difference" := GenJnlTemplate."Allow VAT Difference";

Cascade record deletion

When a record from the Gen. Journal Template table is deleted, the corresponding Gen. Journal Batch and Gen. Journal Line records are also deleted.

Cascade updates

When the reason code or the posting number series change in the current batch, all linked Gen. Journal Line records are updated (see ModifyLines function on the Gen. Journal Batch table).
The Gen. Journal Line table (814) stores a relation with the Journal Batch Name field (51) in the Gen. Journal Batch table. The Gen. Journal Line table also inherits the table relation with the Journal Template Name field (1) in the Gen. Journal Template table.

NAV Usages

Implementations of this pattern in NAV include:
  • General Journal 
  • Item Journal
  • Resource Journal
  • Job Journal

Reference from community.dynamics.com

metadata in Dynamics NAV

A set of data that describes and gives information about other data.

In NAV,
if the object is compiled, a metadata will be specified.

We need metadata because, its used on NAV Server to allow running and debugging the object.


Ex:
If you have a table 18 customer, a record will be created for that when you compile it,



  • If the record(metadata) is missing for an object, then you cannot run object on NAV server.
  • when you compile an object in development environment. Record(metadata) is automatically generated.

Metadata field, Object metadata table.

Specifies XML metadata for the object. This allows the object to be run on Dynamics NAV Server.



  • Metadata is stored in Table 2000000071 object metadata for all navision objects whether it is visible or hidden. 
  • usually system table "Object Metadata" is created when we restore the database after creating the keys for various tables while processing the objects.
  • For visible objects these metadata's are automatically created when we compile the particular object. 

How to reduce Impact on Server and Network traffic.

To reduce impact on server :

1. COMMIT Function : Usually they're automatically handled by database. So avoid using it as much as possible.

2. LOCKTABLE Function : During inserting, modifying, renaming and deleting a data in a table. The SQL Server will automatically locks the table. So, avoid using it.

Example :

Consider a Customer table-

Developer A will check the cost between 10,000 to 50,000. If necessary he 'll modify some value.

If Developer B is also working on same database and same Customer table, modifying the value by Developer B will also affect the changes of Developer A. So, Developer A will lock the table while working or retrieving any value from table.

But, since SQL Server will lock the table automatically when you try to modify the data. Hence, avoid using LOCKTABLE function.



3. Don't examine(or verify) return values of insert, modify, delete function, If it is examined server must be notified.

4. Avoid Roundtrips to the servers.
Round trips - A round trip consists of a request sent to the server for data or an action (whenever a call to insert/modify/delete trigger for an action it takes time and resources which impacts on server.

4. Use CALCSUMS and CALCFIELDS function - Use it whenever you get a chance, to avoid examining records to total values.

5. Use SETAUTOCALCFIELDS function - Whenever you need to obtain value of flowfield for every single row in loop.


To reduce Network Traffic :

1. Apply keys and filters, and use MODIFYALL and DELETEALL functions instead of using modify and delete for each record.

2. To perform calculation on server fields that have single function call, use CALCSUMS and CALCFIELDS (both will take multiple parameters)


Extended stored procedure error (xp_ndo.dll and xp_ndo_x64.dll) in NAV 2009

Ever you faced a problem when you try to open the NAV 2009 database which says,

"The extended stored procedure xp_ndo_enumusersids in the library file xp_ndo.dll, is not available on the <server name> server."

Well, if you've faced this above error then the solution for that is very simple. :)
Firstly identify where are those dll files and copy that to your local machine.

You can find xp_ndo.dll and xp_ndo_x64.dll in the following path of NAV 2009 R2 installation folder.
D:\2009R2\SQLDatabase\PFiles\Microsoft Dynamics NAV\60\Database\Cronus.flf


Once you copy the above .dll files in your local folder. Open SQL Server and go to,

Databases -> System Databases -> Master -> Programmability -> Extended stored procedures,

1. Create a new Extended stored procedure in that,

Give a stored procedure name as xp_ndo_enumuserids
and DLL path (the path you the .dll file) - xp_ndo.dll  (This dll file is 32 bit)

Go to permission click search and choose public.
Selecte Execute, Grantor - dbo and tick mark Grant.

2. Again, Create a new Extended stored procedure, go to properties in that,

Give a stored procedure name as xp_ndo_enumusergroups
and DLL path(the path you the .dll file) - xp_ndo_x64.dll  (This dll file is 64 bit)

Go to permission click search and choose public.
Selecte Execute, Grantor - dbo and tick mark Grant.

Fig. below explains in detail.

Once you are done with this go back to your NAV. Try to open the database of 2009R2 and you will be good to go further with your work.


2026 Release Wave 1(28.0) Major Update in Business Central That Actually Help Clients

This release is not about “new screens.”  It’s about running the business with fewer surprises and more confidence. 1. Smarter Work with C...