Skip to main content
Inspiring
January 24, 2021
Question

Extendscript and FM2020: 2 functions can't be run on PostSaveDoc

  • January 24, 2021
  • 2 replies
  • 880 views

Hello fellows,

I hope everybody is healthy and doing well!

I have an event-driven script that is supposed be triggered upon a PostSaveDoc notification (see the code below). What the SaveAsFM13 function does is quite obvious. The SyncFM() function just copies the file to a network folder. The problem is that one function is executed only when the other one is not called. Both of them cannot be executed when saving a file. Why can't these functions coexist and be executed one after another? Thanks for your input in advance!

 

var doc = app.ActiveDoc;

//Register for notification
Notification(Constants.FA_Note_PostSaveDoc, true);

//Handle notification
function Notify(args, object, sparam, iparam)
{
  object.IsOnScreen = 1;
  
  switch (args)
         {
                case Constants.FA_Note_PostSaveDoc:       
                   SaveAsFM13(object, sparam);     
                   SyncFM(object);                  
                 break;       
         }
}

...

 

    This topic has been closed for replies.

    2 replies

    Klaus Göbel
    Legend
    January 26, 2021

    Hi Rom_Ba,

    you say, both functions work as standalone.

    I've tested them and function SaveAsFM13 i got an error -44.

    So with the parameters you have you have to change the name of the file.

    I've done sth. like:

    var NewName = file.Name.replace(".fm","_NEW.fm");
    
    file.Save(NewName, params, returnParamsp);

    and it works.

    Tested in FrameMaker 2019 and 2020.

     

     

    Rom_BaAuthor
    Inspiring
    January 26, 2021

    Hi Klaus,

    I appreciate your response!

    That's quite surprising as I don't get any error at all (Result: undefined). Why would one need to change the file name?

     

    Cheers,

    Roman

    Klaus Göbel
    Legend
    January 26, 2021

    Hi Roman,

    you used parameter FV_ModeSaveAs and not FV_ModeSave. So save as means (as I understand) that you save a file with a different filename. Different filename can also mean same name (document.fm), but different path (~fm13\document.fm).

     

    frameexpert
    Community Expert
    Community Expert
    January 25, 2021

    They should be able to work in the way you describe. However, something about the object parameter may be changing in the SaveAsFM13 function. You may want to return something from that function that the SyncFM can use. For example,

     

    doc13 = SaveAsFM13(object, sparam);
    SyncFM(doc13);

     

    Rom_BaAuthor
    Inspiring
    January 25, 2021

    Hi Rick,

    Thank you for your response! What could be changing in the SaveAsFM13 function? Here is its code. I don't see anything special about it. Thank you!

     

    function SaveToFM13(file) 
    {	
        if(file.ObjectValid()) 
        {
            var params = GetSaveDefaultParams();
            var returnParamsp = new PropVals();
            var i;
            i = GetPropIndex(params, Constants.FS_FileType);
            params[i].propVal.ival = Constants.FV_SaveFmtBinary130;
            i = GetPropIndex(params, Constants.FS_SaveAsModeName);
                params[i].propVal.ival = Constants.FV_SaveAsNameProvided;
            i = GetPropIndex (params, Constants.FS_SaveMode);
                params[i].propVal.ival = Constants.FV_ModeSaveAs;
            file.Save(file.Name, params, returnParamsp);
            alert("Error: " + FA_errno);
            return; 
            }
    }

     

    Legend
    January 25, 2021

    I ran a test using your code and the document object does not seem to change. I was able to use it after the SaveAsFM13() function. At least, I was able to close it with object.Close().  So, it seems something else is going on.