These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Need Help!! Is there a way to check if the SaveAs action was completed?

taniamc
Registered: Mar 26 2011
Posts: 24
Answered

Hi folks
I have a button that, when pressed:
1.) Locks a selection of fields
2.) Hides 2 different buttons
3.) Launches a Save-As dialgoue
4.) Hides the button preforming all of this.
 
Everything is working great, but I have noticed that if the user presses "cancel" on the save-as dialogue, the script continues to run. This would be fine except that now all the buttons are hidden and there is no way for the user to "re-run" the script. The first action is javascript and the second, third, and forth actions are actual built in actions. Is there a way to script this so that Action 4 does not happen unless the user successfully saves their file?
 
I think I can figure everything out, if someone can just help me figure out a test to know if the file was successfully saved or if the dialog was canceled.
  
Thanks! I have found SO many answers on this forum! You guys rock!

My Product Information:
Acrobat Pro 9.3, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Accepted Answer
The "dirty" property of a file will be true if the document has been changed in a way that requires saving.
So if saveAs is completed, and no other changes are made, this.dirty should return false.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

taniamc
Registered: Mar 26 2011
Posts: 24
try, I appreciate your help with this. This is a very clever way to approach my problem, and of course... I didn't think of it! I don't think I'm coding the "check" correctly though, and it's probably b/c I'm not familiar with the dirty property of a document.

if (this.dirty==false){
--hide buttons--
}
else {
-- blah --
}

What am I missing?
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Seems ok to me... Is it not working? Try printing this.dirty to the console to make sure it has the correct value.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

taniamc
Registered: Mar 26 2011
Posts: 24
Ah, I was just being a dunce. It is working now! Thanks so much!
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
You could also use the 'Did Save' document action.

George Kaiser

taniamc
Registered: Mar 26 2011
Posts: 24
George, this worked for what I needed, but I am quite curious about the Did Save document action you mentioned. Where can i find this?
taniamc
Registered: Mar 26 2011
Posts: 24
Oh, interesting, I found it. Strange to be where it is, I never would have thought to look there. Is there an advantage to doing it this way or the other?

I have decided I would like to ad a dialog window that says "Document saved! Your form is ready for distribution." if it saves and a "Oops, you form is ready for distribution, but you did not save it!" otherwise. The this.dirty is not working properly for this, it triggers the "Oops" dialog no matter what.


if (this.dirty = false) {
var oDlg =
{
description:
{
name: "Success!",
elements:
[
{
name: "success!",
type: "static_text",
},
{
type: "ok",
},
]
}
};
// Dialog Activation
app.execDialog(oDlg);
}
else {
var oDlg2 =
{
description:
{
name: "Uh oh",
elements:
[
{
name: "failed.",
type: "static_text",
},
{
type: "ok",
},
]
}
};
// Dialog Activation
app.execDialog(oDlg2);
}

gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
It is easier to detect the trigger event 'Save' or 'Save as' even when there is no specific button. It might be hard to detect a failed save action. But it could be possible to use a document level variable to keep track if the save last save was successful or not and then take some action at the 'Will Close' event.

It is hard to tell why your use of 'this.dirty' is not working correctly. Perhaps there is some other action you form is doing that is causing the 'dirty' property to be modified.

The equality operators are '==' and '==='.

The '=' is the set operator and is causing the 'dirty' property to be set to false.

George Kaiser

taniamc
Registered: Mar 26 2011
Posts: 24
I see how that I had missed a "=" in my if statement. Rookie mistake, how embarrassing.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4307
if (this.dirty = false) {

Should be coded as:

if (this.dirty == false) {

Your code is setting the dirty property to false not testing the value of the property.

George Kaiser

taniamc
Registered: Mar 26 2011
Posts: 24
Sorry about that, I saw the error of my ways.
try67
Expert
Registered: Oct 30 2008
Posts: 2398
I see just now that you mentioned that the action you want to prevent if the file is not saved is a built-in action, not JS.
If that's the case then you can't prevent it from happening from within your code. You will need to convert it to actual JS code (which is easily done, in this case) to make it dependent of the "dirty" property.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com