Financials 1.20 question

Fred_DeutschFred_Deutsch Member Posts: 51
edited 2006-04-20 in Navision Financials
I am trying to track report usage, I have noticed that running any report triggers CodeUnit 1 - Application Management.FindPrinter, passing the report ID. So, I made a new Table "Report Usage" with two fields "ReportID" and "Frequency" - both integers, then added this code to CodeUnit 1 - Application Management.FindPrinter:


IF ReportUsage.GET(ReportID) THEN BEGIN
ReportUsage.Frequency := ReportUsage.Frequency + 1;
ReportUsage.MODIFY;
END
ELSE BEGIN
ReportUsage.INIT;
ReportUsage."Report ID" := ReportID;
ReportUsage.Frequency := 1;
ReportUsage.INSERT;
END;

If I run any report from the std menus, this seems to work fine, however running reports directly from the Object Designer gives the following Error:

"You cannot make changes to the Database from this trigger"
This happens regardless of whether the report has been run before or not.

Oops forgot to say I also specifically added permisson to modify/insert the ReportUsage Table to both the codeunit 1 as well as to all users.

Any ideas why and how to fix this would be greatly appreciated.

Comments

  • krikikriki Member, Moderator Posts: 9,112
    And do you have the error when you run the report from the menu or another object?
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Morten_SolbergMorten_Solberg Member Posts: 24
    here is a solution:


    make a vbscript who write a log:
    use the FileSystemObject

    CodeUnit 1:
    In the FindPrinter Trigger


    insert code before the EXIT function:

    str := STRSUBSTNO('wscript c:\myReportLog.vbs %1',ReportID);
    SHELL(str);

    EXIT(PrinterSelection."Printer Name");



    the vbscript:

    Option Explicit
    On Error Resume Next
    Dim ReportID
    Call fctGetParameters
    Call WriteLog(ReportID)

    Sub WriteLog(parReportID)
    Dim FSO, FileTxt
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Const FileName = "C:\ReportLog.txt"
    Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
    Set FileTxt = FSO.OpenTextFile(FileName, ForAppending, True)
    FileTxt.WriteLine("then text comes here: including reportID: " & parReportID)
    FileTxt.Close
    Set FSO = Nothing
    End Sub

    Sub fctGetParameters
    Dim objArgs
    Set objArgs = WScript.Arguments
    ReportID = objArgs(0)
    End Sub
  • krikikriki Member, Moderator Posts: 9,112
    And in the script, you can let it write in a way so it is easily opened with Excel and have some statistics on it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Fred_DeutschFred_Deutsch Member Posts: 51
    kriki wrote:
    And do you have the error when you run the report from the menu or another object?

    No, and thats what I find so curious.
  • Fred_DeutschFred_Deutsch Member Posts: 51
    here is a solution:
    make a vbscript who write a log:
    use the FileSystemObject

    I thought of that but I see a few problems, we have nearly 50 users, so each user would have to have a copy of the script on their workstation, then I'd have 50 seperate logs to assemble. Also about half of our users are remoted in via Metaframe / NT 4 TS, which makes strange drive letter assignments and may have problems running VB or VB Script. I may not have a choice though. I'm mainly curious as to why running a report directly from the Designer errors, while running a report from the Reports Menu or a form does not error. Time to enable the Debugger again I guess.
  • krikikriki Member, Moderator Posts: 9,112
    here is a solution:
    make a vbscript who write a log:
    use the FileSystemObject

    I thought of that but I see a few problems, we have nearly 50 users, so each user would have to have a copy of the script on their workstation, then I'd have 50 seperate logs to assemble. Also about half of our users are remoted in via Metaframe / NT 4 TS, which makes strange drive letter assignments and may have problems running VB or VB Script. I may not have a choice though. I'm mainly curious as to why running a report directly from the Designer errors, while running a report from the Reports Menu or a form does not error. Time to enable the Debugger again I guess.
    You can create a textstring at runtime and then give that string to the script.
    variable : LautScriptControl Automation 'Microsoft Script Control 1.0'.ScriptControl
    and "LtxtScript" contains your script.
    CREATE(LautScriptControl);
    LautScriptControl.Language := 'VBScript';
    LautScriptControl.ExecuteStatement(LtxtScript);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Fred_DeutschFred_Deutsch Member Posts: 51
    kriki wrote:
    here is a solution:
    make a vbscript who write a log:
    use the FileSystemObject

    I thought of that but I see a few problems, we have nearly 50 users, so each user would have to have a copy of the script on their workstation, then I'd have 50 seperate logs to assemble. Also about half of our users are remoted in via Metaframe / NT 4 TS, which makes strange drive letter assignments and may have problems running VB or VB Script. I may not have a choice though. I'm mainly curious as to why running a report directly from the Designer errors, while running a report from the Reports Menu or a form does not error. Time to enable the Debugger again I guess.
    You can create a textstring at runtime and then give that string to the script.
    variable : LautScriptControl Automation 'Microsoft Script Control 1.0'.ScriptControl
    and "LtxtScript" contains your script.
    CREATE(LautScriptControl);
    LautScriptControl.Language := 'VBScript';
    LautScriptControl.ExecuteStatement(LtxtScript);
    

    I'm sorry but I do not understand this post - is the code above Navision Code ? Remember this is Financials US1.20, there is no Variable Type "Automation"
  • krikikriki Member, Moderator Posts: 9,112
    I'm sorry but I do not understand this post - is the code above Navision Code ? Remember this is Financials US1.20, there is no Variable Type "Automation"
    :oops: Forgot a moment that it is version 1.20.
    Yes it is Navision code, but for later versions.
    You might do a technical upgrade to 4.0SP1 so you can use automation. :whistle:
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • Fred_DeutschFred_Deutsch Member Posts: 51
    Can you explain a "Technical Upgrade" ? - I was under the impression that any upgrades require complete recoding of all modifications (of which we have many) - also, when MS bought Navision, we opted NOT to continue the support and resource availibility options but instead bought lots of user sessions, forms, tables, reports, etc and upped our license to the highest level below developer. I was also told that this meant that to get any upgrades, we would have to pay all old fees to get current.
  • ara3nara3n Member Posts: 9,256
    Then find out until what version you were you on support. My guess 3.6 or 3.7. Then get that executables and install them. Open the backup database with the new client. It will ask you to upgrade, select yes, and you just did a technical upgrade. You have to make sure that you don't have the same name on the objects if you do, you need to rename them. Make sure it works with your license. Also Automation is a granuale. I don't know if you would have it on your license.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.