2 Replies Latest reply on Jun 29, 2016 9:07 AM by K.Daube

    How to unregister script programmatically ?

    K.Daube Level 1

      Friends, Romans, Countrymen!

      Lend me your ears! [Shakespeare: Julius Cesar]


      During testing a script wich has a notification It is necessary to uninstall it every time before it is run again (after some modification). Doing this via the script catalog is at least time consuming.

      If I do not do this, then old code may be executed and the Data Browser shows items which are no more in the script...I even have to start FM and the ESTK again and again during the tests. In the Notify function it is also not possible,

      • to set a breakpoint
      • to use $.writeln.

      The only feedback functions are alert, Alert and Console. It is, however, possible to set a breakpoint in a called function. Since some of them are called from the Notify function I need to place several...

      I have tried to place the unregistering code at the Cancel button of the dialogue the functions of which I'm testing:

      wPalDS.g1.Cancel.onClick = function () {
        Notification (Constants.FA_Note_PostActiveDocChange, false);   // unregister script

      But this does not work - the script is still registered after cancelling.

      For debugging the Scripting Guide refers to the JavaScript Tools Guide - which does not touch such delicate situations at all.


      Do You have a trick to see both the global items and the local (to a function) variables and objects in the Data Browser? Currently I use such constructs as var a1 ...:

      function RefreshGlobalsDS () {
        GetRefPageItems ("Ref-Locations");              // gasLocations
        GetRefPageItems ("Ref-Formats");                // gasFormats
        GetRefPageItems ("Ref-Schemes");                // gaoTxtSchemes
      var a1 = gasLocations, a2 = gasFormats, a3 =  gaoTxtSchemes;
        FillItemList (wPalDS.p0.tabL.g1.p1.listLocations,  gasLocations);  // undefined is not an object ????
        FillItemList (wPalDS.p0.tabF.g1.p1.listFormats,    gasFormats);
        FillSchemeList (wPalDS.p0.tabT.g1.p1.listSchemes,  gaoTxtSchemes);

      Any tips and tricks at hand?

        • 1. Re: How to unregister script programmatically ?
          Klaus Göbel Level 3

          Hi Klaus,


          did you try to swap lines2 and 3 ?

          First remove thenotification ?


          I do it like this:


          wPalDS.onClose = RemoveMyNotification;


          function RemoveMyNotification()
          Notification(Constants.FA_Note_PostActiveDocChange, false);


          Just give it a try.

          • 2. Re: How to unregister script programmatically ?
            K.Daube Level 1

            Thank You, Klaus!

            Have placed wPalDS.onClose = RemoveMyNotification; in the dialogue towards the end.

            This works as intended!


            However, I have to think more about this: In the final script it will be to early to unregister at closing the dialgoue. The user may choose to use another menu-item thus opening another dialogue or issuing another function - and the script is no more registered and hence will not react on change of document.

            For the final version it may be best to unregister at the close of the FM session. But for now it's a releaf.