Microsoft Office Forums


Reply
Thread Tools Display Modes

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

 
 
ISUComSciGuy
Guest
Posts: n/a

 
      12-05-2007, 04:48 PM
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?
 
Reply With Quote
 
 
 
 
S.Y.M. Wong-A-Ton
Guest
Posts: n/a

 
      12-06-2007, 06:40 AM
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.
---
S.Y.M. Wong-A-Ton


"ISUComSciGuy" wrote:

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

 
Reply With Quote
 
ISUComSciGuy
Guest
Posts: n/a

 
      12-06-2007, 04:19 PM
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)?

---

Walter

 
Reply With Quote
 
S.Y.M. Wong-A-Ton
Guest
Posts: n/a

 
      12-07-2007, 05:07 AM
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/lib...ffice.11).aspx
---
S.Y.M. Wong-A-Ton


"ISUComSciGuy" wrote:

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

 
Reply With Quote
 
ISUComSciGuy
Guest
Posts: n/a

 
      12-07-2007, 03:50 PM
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

 
Reply With Quote
 
S.Y.M. Wong-A-Ton
Guest
Posts: n/a

 
      12-07-2007, 09:53 PM
No worries. Thanks, and you too have a great holiday season!
---
S.Y.M. Wong-A-Ton


"ISUComSciGuy" wrote:

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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Save button (JScript) not working ISUComSciGuy Infopath Newsgroup 0 12-04-2007 08:47 PM
Conversion from JScript to C# - Infopath2007 - urgent please help Dotnetdev Infopath Newsgroup 4 07-05-2007 01:10 PM
Urgent please: What save format to use Soccerman58 Visio Newsgroup 4 04-05-2006 02:09 PM
XDocument.SaveAs Method with Property IsSaveAs = false maor110 Infopath Newsgroup 0 08-19-2005 02:20 PM
Display the SaveAs Dialog with a jscript code Tom Infopath Newsgroup 1 08-16-2005 08:36 AM



All times are GMT. The time now is 02:17 PM.