• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Stuck with Notify / registered script

Community Expert ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

461

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jun 14, 2016 Jun 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

Votes

Translate

Translate
Enthusiast ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 14, 2016 Jun 14, 2016

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines