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