field always empty!

nvermanverma Member Posts: 396
I have created a codeunit and this codeunit is executed after every minute.
  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?

Answers

  • mohana_cse06mohana_cse06 Member Posts: 5,504
    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;
    
  • nvermanverma Member Posts: 396
    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/r2bw0tpe11ed
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    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;
    
  • nvermanverma Member Posts: 396
    how stupid off me...i didnt think about repeat and until statements after findset...and it worked now....
  • nvermanverma Member Posts: 396
    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???
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    What about
    LicensePercentage := (MaximumUsers / LicenseUserCount) * 100;
    
  • nvermanverma Member Posts: 396
    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...
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    nverma wrote:
    That is how I actually did it initially, but it always gave me 'divide by zero' ERROR.
    it means that your LicenseUserCount value is zero.
    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...
    Where did ypu write code to get the "Users Logged On" record?
  • nvermanverma Member Posts: 396
    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;
    
  • mohana_cse06mohana_cse06 Member Posts: 5,504
    So how many records you have in "Users Logged On" table?

    Are there any flowfields?
  • nvermanverma Member Posts: 396
    Nevermind....i made a silly mistakes...thats why it didnt work....I just fixed it and now it works like a charm...

    Thanks...
Sign In or Register to comment.