How to create unique records in navision

Vamshi_ydv
Member Posts: 1
i have created a table with fields id,name,roll no,age
id name rollno age
1 A 1 20
2 b 2 20
3 c 1 20
i will create a actiuon called unique
now i have to count unique records in roll no field
like it should show message after clicking on action unique then it should show
"No of unique records is 2"
id name rollno age
1 A 1 20
2 b 2 20
3 c 1 20
i will create a actiuon called unique
now i have to count unique records in roll no field
like it should show message after clicking on action unique then it should show
"No of unique records is 2"
0
Answers
-
If you need to count unique records based on the "rollno" field in NAV, you can achieve this by creating an action and then writing code in C/AL. For this, you will need to use a "Record" and "Dictionary of [Integer, Integer]"
Please note that the "Dictionary" object is part of the .NET framework which can be accessed using C/AL DotNet variables. Here is an example
1. Create a new action in your Page. You can name it "Count Unique Roll Numbers".
2. For this action, create the "OnAction" trigger.
3. In the "OnAction" trigger, write the following code:PROCEDURE "Count Unique Roll Numbers"(); VAR StudentRec: Record "Your Table ID"; // Replace "Your Table ID" with the actual ID of your table Dict: DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Generic.Dictionary`2"; Message: Text[100]; BEGIN Dict := Dict.Dictionary(); IF StudentRec.FINDSET THEN REPEAT IF NOT Dict.ContainsKey(StudentRec.rollno) THEN Dict.Add(StudentRec.rollno, StudentRec.rollno); UNTIL StudentRec.NEXT = 0; Message := STRFORMAT('No of unique records is %1', Dict.Count); MESSAGE(Message); END;
This code creates a "Dictionary" (an object from .NET framework which is a collection of keys and values), then iterates over your table's records. For each record, it checks if its "rollno" is already in the "Dictionary". If it's not, it's added. After going through all records, the count of keys in the "Dictionary" is the count of unique "rollno's".
After this action is run, it will display a message stating the number of unique roll numbers in the table.
Remember, this process only checks for uniqueness in the "rollno" field when you run the action. If you want to enforce uniqueness at the time of data entry, you would need a different approach (like adding code to the "OnValidate" trigger for the "rollno" field).0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions