Skip to main content
Inspiring
Jan 24, 2021 2:01 PM UTC
Question

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

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 is closed to new replies. Start a new post to keep the conversation going.

    11 replies

    Klaus Göbel
    Legend
    Jan 26, 2021 4:20 PM UTC

    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.

     

     

    Translate
    Rom_BaAuthor
    Inspiring
    Jan 26, 2021 5:15 PM UTC

    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

    Translate
    Klaus Göbel
    Legend
    Jan 26, 2021 7:49 PM UTC

    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).

     

    Translate
    frameexpert
    Community Expert
    Community Expert
    Jan 25, 2021 12:32 PM UTC

    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);

     

    Translate
    www.frameexpert.com
    Rom_BaAuthor
    Inspiring
    Jan 25, 2021 12:52 PM UTC

    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; 
            }
    }

     

    Translate
    Legend
    Jan 25, 2021 1:33 PM UTC

    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.

    Translate