Urgent: XDocument.Save() or .SaveAs (JScript) Not supported

I

ISUComSciGuy

I am trying to add a save button to a form. I've signed the form and given
it FULL TRUST within the Form Option menu item. But the code throws the
following error:

Object doesn't support this property or method
File:script.js
Line:44

Is there something I'm missing or do I need to change a security setting?
 
S

S.Y.M. Wong-A-Ton

What's on line 44? What version of InfoPath are you using? The error does not
have anything to do with trust. It is just telling you that the object that
you are using does not support the property or method that you are calling on
it.
 
I

ISUComSciGuy

Thank you for your reply, line 44 had the call to XDocument.Save(). I've
alter the code slightly since the last post, but am still receiving an error.
Below is the code causing the error (I've simplified the code as much as
possible)

----------------------------------------------------
function XDocument::OnSaveRequest(eventObj)
{
var filePath = "file:///C:/";
var fileName = XDocument.View.Name + ".xml";
var fileURL = filePath + fileName;

XDocument.UI.SetSaveAsDialogLocation(filePath);
XDocument.UI.SetSaveAsDialogFileName(fileName);

eventObj.IsCancelled = eventObj.PerformSaveOperation();

if (eventObj.IsCancelled)
{
XDocument.UI.Alert("Save Cancelled");
}
else
{
XDocument.UI.Alert("Form saved");
}

eventObj.ReturnStatus = true;
}

function CTRL86_5::OnClick(eventObj)
{
XDocument.Save();
}

The following error occurred:

InfoPath cannot save the form.
The OnSaveRequest function returned a value indicating that the save failed.
The following error occurred:

The form does not have a file name.
File:script.js
Line:26
----------------------------------------------------

I'm trying to prevent the user from having to manually enter the file name
and file location and save the form with a single click. If the user click
on the save command on the tool bar (instead of the button), the SaveAs
dialog appears with the correct file name and file location. The error only
appears when the user clicks the custom save button.

I've tried to code the button with the code to produce the fileURL and to
use the XDocument.SaveAs(fileURL) instead, but the same error pops up.

However, if I use the SaveAs call in the button code (coding the file name
in the button method and passing it the the SaveAs method), but do not use
the custom save code in the OnSaveRequest() method (i.e. I deselect the Save
using custom code on the File Option -> Save and Open tab) it works fine.

Bottom line, can you use the Save or SaveAs method call from a button method
and also use custom save code? And if you can, how (please include code
sample)?
 
S

S.Y.M. Wong-A-Ton

You did not tell me which version of InfoPath you're using. If you're using
2003, do you have SP1 installed?

While the docs say that you should be able to use the two together
(Save/SaveAs and OnSaveRequest), I have never seen it work. The
XDocument.Save() will work if you have previously saved the form. If you
haven't previously saved the form, you must catch the error that it raises
and try using the XDocument.SaveAs() method. So you must do something like
the following in your button:

try
{
XDocument.Save();
}
catch (e)
{
XDocument.SaveAs("<path_to_file>");
}

Where code is concerned, you can do a search in this newsgroup or take a
look at this article:
http://msdn2.microsoft.com/en-us/library/bb608308(office.11).aspx
 
I

ISUComSciGuy

Thanks for your reply; I am using InfoPath 2003 SP2. It's really frustrating
the two don't actually work together. Hopefully, this will be corrected in
future releases. It would also be nice if the XDocument.SaveAs() method
displayed the SaveAs dialog and verified file overwrites.

Thanks again, and I hope you have a good holiday season.

Walter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top