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

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

Explorer ,
Jan 24, 2021 Jan 24, 2021

Copy link to clipboard

Copied

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

...

 

Views

374

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 ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

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

 

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
Explorer ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

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

 

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
Mentor ,
Jan 25, 2021 Jan 25, 2021

Copy link to clipboard

Copied

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.

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
Explorer ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

Hi Russ,

Thank you for your response!

How can the object change during the save operation so that it could no longer be copied to another folder using the SyncFM function?

It is important to note that both of the functions work perfectly when run separately.

Thanks,

Roman

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
Explorer ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

Hi Rick,

 

I tried your suggestion, but in this specific case I saw no difference in the result. Maybe the issue is somehow related to the type of notification I am using?

 

Thanks,

Roman 

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 ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

I would put some debug code in the second function to see where it is failing. Do you get an messages to the FrameMaker Console that indicate an undefined object or some other error?

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
Enthusiast ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

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.

 

 

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
Explorer ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

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

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
Enthusiast ,
Jan 26, 2021 Jan 26, 2021

Copy link to clipboard

Copied

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

 

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
Mentor ,
Jan 27, 2021 Jan 27, 2021

Copy link to clipboard

Copied

Well, I don't get any error when I run the function in FM2019. It saves the file as the old version with the same filename. FA_errno=0. I still think something else is going on.

 

Maybe is it possible that something strange is happening because you are saving a document upon a PostSaveDoc notification? I almost think that should cause an endless loop 🙂

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
Explorer ,
Feb 09, 2021 Feb 09, 2021

Copy link to clipboard

Copied

LATEST

Hi Russ,

Thank you for your response!

I actually tried both PostSaveDoc and PreSaveDoc - no difference.

 

Regards,

Roman

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