field always empty!
nverma
Member Posts: 396
I have created a codeunit and this codeunit is executed after every minute.
I am trying to keep track of the total number of application servers that are running. However, no matter what I do, the application name is always empty therefore, it never executes the if statement and thus it never increments the current nas users. Any idea what I might be doing wrong?
Session.SETFILTER("Database Name", '%1|%2', 'MODC - Live', 'MODC - Development');
UsersLoggedOn.INIT;
UsersLoggedOn."Current Users" := Session.COUNT;
UsersLoggedOn.Time := TIME;
UsersLoggedOn.Date := TODAY;
IF Session."Database Name" = 'MODC - Live' THEN
[b] IF Session."Application Name" = 'Application Server for Microsoft Dynamics NAV Classic' THEN
[/b] BEGIN
UsersLoggedOn."Current NAS Users" += UsersLoggedOn."Current NAS Users";
END;
UsersLoggedOn.INSERT;
I am trying to keep track of the total number of application servers that are running. However, no matter what I do, the application name is always empty therefore, it never executes the if statement and thus it never increments the current nas users. Any idea what I might be doing wrong?
0
Answers
-
Did you try
Session.SETFILTER("Database Name", '%1|%2', 'MODC - Live', 'MODC - Development'); UsersLoggedOn.INIT; UsersLoggedOn."Current Users" := Session.COUNT; UsersLoggedOn.Time := TIME; UsersLoggedOn.Date := TODAY; IF Session.FINDFIRST THEN //New Line IF Session."Database Name" = 'MODC - Live' THEN [b] IF Session."Application Name" = 'Application Server for Microsoft Dynamics NAV Classic' THEN [/b] BEGIN UsersLoggedOn."Current NAS Users" += UsersLoggedOn."Current NAS Users"; END; UsersLoggedOn.INSERT;0 -
I tried what you suggested....by adding that line...it only finds the first record that meets the setfilter criteria...it doesnt loop throught all of them......so it doesnt work...then i tried using a findset...but that didnt work aswell...
looking at the picture might give you a better idea...
http://www2.zshare.ma/r2bw0tpe11ed0 -
Did ypu try REPEAT UNTIL with FINDSET?
Session.SETFILTER("Database Name", '%1|%2', 'MODC - Live', 'MODC - Development'); UsersLoggedOn.INIT; UsersLoggedOn."Current Users" := Session.COUNT; UsersLoggedOn.Time := TIME; UsersLoggedOn.Date := TODAY; IF Session.FINDSET THEN //New Line REPEAT //New Line IF Session."Database Name" = 'MODC - Live' THEN IF Session."Application Name" = 'Application Server for Microsoft Dynamics NAV Classic' THEN BEGIN UsersLoggedOn."Current NAS Users" += UsersLoggedOn."Current NAS Users"; END; UNTIL Session.Next = 0; //New Line UsersLoggedOn.INSERT;0 -
how stupid off me...i didnt think about repeat and until statements after findset...and it worked now....0
-
i have a quick question...this is the code from a report that uses that codeunit that is mentioned in this thread...
IF (MaximumUsers < "Users Logged On"."Current Users") THEN BEGIN MaximumUsers := "Users Logged On"."Current Users"; PeakTime := "Users Logged On".Time; TodaysDate := "Users Logged On".Date; LicenseUserCount := "Users Logged On"."License User Count"; LicenseNASCount := "Users Logged On"."License NAS Count"; CurrentNASCount := "Users Logged On"."Current NAS Users"; IF (LicenseUserCount = 0) THEN LicensePercentage := 0 ELSE LicensePercentage := (MaximumUsers DIV LicenseUserCount)*100; END;
LicensePercentage doesnt work. Its always 0 for some reason. I tried debugging it, and maximumUser has a value and licenseusercount has a value aswell...but it doesnt calculate the licensepercentage...any idea why???0 -
What about
LicensePercentage := (MaximumUsers / LicenseUserCount) * 100;
0 -
That is how I actually did it initially, but it always gave me 'divide by zero' ERROR. That is why I wrote the whole IF and else statements to bypass that error message. I was able to bypass the error but my answer was always 0, even thought maximumuser and licenseusercount both had values.
Also I just noticed another issue, in my codeunit I was able to calculate the value for 'Current NAS Users' and when i ran the codeunit, it gave me the correct answer and the answer was put in the table. Now I was trying to display the answer in the report using this line of code and I put CurrentNASCount in the sections of the report:CurrentNASCount := "Users Logged On"."Current NAS Users";
It always displaying 0, no matter what ](*,) ....even though there is a value in the table for this variable for a particular date and time...0 -
it means that your LicenseUserCount value is zero.nverma wrote:That is how I actually did it initially, but it always gave me 'divide by zero' ERROR.
Where did ypu write code to get the "Users Logged On" record?nverma wrote:Also I just noticed another issue, in my codeunit I was able to calculate the value for 'Current NAS Users' and when i ran the codeunit, it gave me the correct answer and the answer was put in the table. Now I was trying to display the answer in the report using this line of code and I put CurrentNASCount in the sections of the report:CurrentNASCount := "Users Logged On"."Current NAS Users";
It always displaying 0, no matter what ](*,) ....even though there is a value in the table for this variable for a particular date and time...0 -
This is the code in the report where i am trying to display the finds from the User Logged On table....and this code is written in OnAfterGetRecord Trigger.
IF (MaximumUsers < "Users Logged On"."Current Users") THEN BEGIN MaximumUsers := "Users Logged On"."Current Users"; PeakTime := "Users Logged On".Time; TodaysDate := "Users Logged On".Date; LicenseUserCount := "Users Logged On"."License User Count"; LicenseNASCount := "Users Logged On"."License NAS Count"; CurrentNASCount := "Users Logged On"."Current NAS Users"; IF (LicenseUserCount = 0) THEN LicensePercentage := 0 ELSE LicensePercentage := (MaximumUsers DIV LicenseUserCount)*100; END;0 -
So how many records you have in "Users Logged On" table?
Are there any flowfields?0 -
Nevermind....i made a silly mistakes...thats why it didnt work....I just fixed it and now it works like a charm...
Thanks...0 -
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
