2 Replies Latest reply on Jun 14, 2016 3:26 AM by K.Daube

    Stuck with Notify / registered script

    K.Daube Level 1

      Dear friends,
      A Notify function is invoked even before I have explicitly started the script. Well this seems to be purpose of registering a script, but...

      The Notify function is executed before the script could initalise and hence I get the message at start of FM (line number according to the code below):

       

      Script Error : 
      Error Message      : wPalC is undefined
      Script, Line#   : E:\_DDDprojects\FM-calc\FM-calc\FM-calc.jsx,  13
      

      (actually this refers to the line 14, because only there wPalC appears.

       

      The Notify routine handles two different dialogues the core of which are set up in functions. Only the window definition is global:

      var wPalC  = new Window('palette',"FM-calc : Handle #Calc Markers",undefined);
      var wPalDS = new Window('palette',"FM-calc : Manage Document Settings",undefined);
      //...
      function SetupNotifications () { // Watch for the following notifications ========================= 
        Notification (Constants.FA_Note_PostActiveDocChange, true);  
      } // --- end SetupNotifications
      
      function Notify (note, object, sparam, iparam) {  // Handle triggered evens =======================
      //$.bp(true);                                     // does not work at all
      //alert ("Notify- object:\n" + object);           // this works
        switch (note) {
          case Constants.FA_Note_PostActiveDocChange:   // active document has changed
            goCurrentDoc = object;
            if (wPalC === undefined) {return;}          // registered script is entered before really started
            if (wPalC.active) {
              if (!object.ObjectValid()) {              // after all documents have been closed
                HideButtonsC ();
                return;}
              giNdexOfMarker = RefreshGlobalsC ();      // later: needs to distinguish marker types !!!
              if (giNdexOfMarker !== null) {
                DisplayMarker (goCurrentDoc, goCurrentMarker);
                wPalC.p0.sMarkerContent.text ="";
                gsMarkerText = goCurrentMarker.MarkerText;
                wPalC.p0.sMarkerContent.textselection = gsMarkerText;
                ActivateButtonsC ();
              } else {
                HideButtonsC ();
              }
              CollectVariables (true);                    // fill the global array
              FillUserVars (wPalC.p0.g1.pVar.listVariables); // fill the diaolgue list
            }
            if (wPalDS.active) {
              CollectVariables (true);                    // fill the global array
              FillUserVars (wPalDS.p0.tabV.g1.p1.listVariables); // fill the diaolgue list
            }
            break;  
        }  
      } // --- end Notify
      

       

      So how to test for an undefined something? Do I need ==== ?-)

      if (!wPalC.ObjectValid())  {return;} 
      

      Does not work either - same error message.

        • 1. Re: Stuck with Notify / registered script
          Klaus Göbel Level 3

          Hi Klaus,

          when you add a notification, you also have to remove the notification.

           

          Register: Notification(Constants.FA_Note_PostMouseCommand,true);

          remove : Notification(Constants.FA_Note_PostMouseCommand,false);

           

          But when your script stops before, you have to remove it manually:

          Go to the script library (file-> script -> library) to unregister a script.

          Otherwise It even stays there even if you restart FrameMaker

          • 2. Re: Stuck with Notify / registered script
            K.Daube Level 1

            Thanks Klaus for this important hint!

            Hoever, the removal of the notification should only be done at Close of the FM-session - hence a nested notification...

             

            ... and I have found how my test should be coded:

            if (typeof  wPalC === "undefined")  {return;}
            

            xxx