Skip to main content
K.Daube
Community Expert
Community Expert
June 14, 2016
Answered

Stuck with Notify / registered script

  • June 14, 2016
  • 1 reply
  • 698 views

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.

This topic has been closed for replies.
Correct answer Klaus Göbel

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

1 reply

Klaus Göbel
Klaus GöbelCorrect answer
Legend
June 14, 2016

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

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
June 14, 2016

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