OnSaveRequest function - InfoPath Dev
in

InfoPath Dev

OnSaveRequest function

Last post 11-28-2005 02:55 PM by Patrick Halstead. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 06-14-2005 12:47 AM

    • hudsucker
    • Not Ranked
    • Joined on 06-14-2005
    • United Kingdom
    • Posts 6

    OnSaveRequest function

    Only just started dabbling with InfoPath. I am currently designing a form that needs to be saved to a specific location with a specific reference id as the file name which is to be taken from a field within the form. But alas, as you might have guessed, it does not work for me.

    I have followed steps outlined in the article Extending the Save Functionality in InfoPath 2003

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_ip2003_ta/html/odc_InfoPath_extending_save.asp

    This document describes how to add script through Tools - Form Options > Open And Save > Save Behaviour > Save using custom code

    The code I have used is as follows:

    Sub XDocument_OnSaveRequest(eventObj)

    ' Write the code to be run before saving here.

    Dim GMSRef
    GMSRef = thisXDocument.DOM.selectSingleNode("//my:myfields/my:field5").text
    If thisXDocument.IsNew = True or eventObj.IsSaveAs = False then
    If eventObj.IsSaveAs = True then
    thisXDocument.UI.SetSaveAsDialogLocation("f:\Windows Infrastructure\Inspection Form")
    thisXDocument.UI.SetSaveAsDialogFileName(GMSRef)
    End If
    eventObj.IsCancelled = eventObj.PerformSaveOperation()
    eventObj.ReturnStatus = true
    Else
    thisXDocument.UI.Alert("The 'Save As' functionality is disabled for forms that are not new.")
    End If

    End Sub


    The error message is as follows:


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

    Object required: 'thisXDocument'
    File:script.vbs
    Line 24


    Line 24 is highlighted red and bold.

    Any help would be gratefully recieved. I know I am doing something daft and it is most likely to do with the way I am using vb.

    Thanks
  • 06-16-2005 02:42 AM In reply to

    Hi.

    I believe the error is being caused due to your XPath command.
    The // will selects nodes in the document from the current node that match the selection no matter where they are.
    In addition you are fully qualifying the node you want.
    Therefore the node is not being located and thus calling the .text method raises an exception.

    Could you try changing your line 24 to;
    GMSRef = thisXDocument.DOM.selectSingleNode("my:myfields/my:field5").text
    Basically remove the //

    cheers. Scott.
  • 06-16-2005 07:22 AM In reply to

    • hudsucker
    • Not Ranked
    • Joined on 06-14-2005
    • United Kingdom
    • Posts 6
    Thanks for the response but it didn't make any difference. Any other ideas?
  • 06-16-2005 07:28 AM In reply to

    Hi.

    Just as a sanity check does my:myfields/my:field5 exist? or is it myFields or Field5. XPath is case sensitive.

    cheers. Scott.
  • 06-16-2005 04:06 PM In reply to

    One other thing is does field5 node contain a value? Please makie sure that it does contain that. Also i would suggest setting some hardcoded value such as abc.xml to GMSRef and verify that the file does get saved.

    This will let us know for sure that its because the value of GMSRef is incorrect that the file is not getting saved. It could be either that it is null or it contains a character that is not suitable for a file name.

    Hope this helps!

    Shanthi
    InfoPathDev India
    Shanthi Reddy
  • 06-17-2005 12:24 AM In reply to

    • hudsucker
    • Not Ranked
    • Joined on 06-14-2005
    • United Kingdom
    • Posts 6
    Hello

    The field does exist and hopefully I am referencing it correctly. In looking at the datasource (main) I have a folder myfields, within it I have the field called field5 which is expecting a string - it has validation ensuring that the field is not left blank.

    I simply added a series of text boxes etc and accepted the default names.

    I can also confirm that myfields and field5 is all lowercase.

    Thanks
  • 06-17-2005 12:30 AM In reply to

    • hudsucker
    • Not Ranked
    • Joined on 06-14-2005
    • United Kingdom
    • Posts 6
    I changed the value of GMSref to abc.xml

    GMSRef = abc.xml
    'GMSRef = thisXDocument.DOM.selectSingleNode("my:myfields/my:field5").text


    The error message changed, only now instead of saying object required is 'ThisXDocument' it was now requiring object "abc.xml"
  • 06-17-2005 02:50 AM In reply to

    Hi. Again just a sanity check. Your code is - DIM GMSRef as string = "abc.xml" Cheers. Scott.
  • 06-17-2005 05:38 AM In reply to

    • hudsucker
    • Not Ranked
    • Joined on 06-14-2005
    • United Kingdom
    • Posts 6
    Well actually the code I am using is:

    Dim GMSRef
    GMSRef = "abc.xml"


    which produces the original error about thisXDocument

    If I use

    Dim GMSRef As String
    GMSRef = "abc.xml"

    or
    Dim GMSRef As String = "abc.xml" 

    it fails to even open the form:

    quote:

    InfoPath cannot open new blank form.
    InfoPath cannot open the selected form because of an error in the form's code.
    The following error occurred:

    Expected end of statement
    File:script.vbs
    Line:25
    DIM GMSRef as string = "abc.xml"
    or
    DIM GMSRef as string


  • 06-17-2005 05:55 AM In reply to

    Sorry my apologies. I see you are using script and not managed code. I have not used InfoPath scripting. Initial questions that spring to mind are;
    * is the thisXDocument object definatly set?
    * does the eventObj parameter provide the XDocument?

    Sorry i cant be of much more use. Cheers. Scott.

  • 06-17-2005 06:48 AM In reply to

    • hudsucker
    • Not Ranked
    • Joined on 06-14-2005
    • United Kingdom
    • Posts 6
    I am simply looking to have a form filed with the unique reference id as entered into the form as the filename and to specify exactly where it is saved to.

    The first obvious choice was as per the link in my first post. If this is not the best way to go can you identify another method. The script is provided by infopath with the sub name etc declared. Evidently the script is not getting details of what thisxdocument is.

    I am really stuck with this and if there is an alternative way to do it then I'll use it.

    Many thanks

    Paul
  • 06-22-2005 08:25 AM In reply to

    Hi Paul.

    Sorry for the delay, i have been out of the office for a few days.

    Here you go http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ipsdk/html/ipsdkIntroducingInfoPathDevelopment_HV01073333.asp

    thisXDocument is not the object in script. Use XDocument;
    GMSRef = XDocument.DOM.selectSingleNode("my:myFields/my:field1").text

    this works for me :)

    Cheers. Scott.
  • 11-22-2005 02:27 AM In reply to

    • frala
    • Not Ranked
    • Joined on 11-09-2005
    • France
    • Posts 16
    Hi,

    The problem I have is not the same but it is regarding the same function.

    The form contents is saved using eventObj.PerformSaveOperation(); method.
    As the user can modify the file name, I would like to save this new file name (a default one is set when the dialog box is opened) in the XDocument.
    I use eventObj.XDocument.URI; to get the new file name but saved XML document is not updated (I agree with that).

    How can I do that ?
    I tried a XDocument.Save(); but it doesn't work (error message).
    If I use again eventObj.PerformSaveOperation(), a new dialog box is opened. Unfortunately the IsSaveAs property is read-only.

    Thanks for your help.
  • 11-28-2005 02:55 PM In reply to

    Save requires higher security. Why do you need to store the value in the XDocument DOM when you can always query the URI when you open the file?

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (14 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.