Newbie with code - InfoPath Dev
in

InfoPath Dev

Newbie with code

Last post 07-09-2009 09:08 AM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 07-08-2009 10:54 AM

    • Mosel
    • Not Ranked
    • Joined on 06-25-2009
    • Posts 12

    Newbie with code

    Hello all!

     I am trying to create a copy request form in IP 2003 and have been able to write some code. When I try to submit the form I get a OBJECT REQUIRED error. I cant figure this out. Here is the code:

    function XDocument::OnSubmitRequest(eventObj)
    {

     var urgency = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requesturgency").text;  
     var personel_last_name = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestfirstname").text;
     var personel_first_name = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestlastname").text;
     var location = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestlocation").text;
     var due = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestcompletion").text;  
     
       
     var type = XDocument.DOM.selectSingleNode("/my:myFields/my:Jobtypegroup").text;
     
     
    try
      {
      var oEnvelope = XDocument.View.Window.MailEnvelope;
     
      oEnvelope.To = "Print&[email protected]";
      oEnvelope.CC = "[email protected]";
      oEnvelope.Subject = "Copy Print & Fulfillment Request - " + type + " - " + personel_last_name + ", " + personel_first_name + " - " + location + " - " + urgency + " - " + due;
      
      oEnvelope.Visible = true;
      }
     catch (ex)
      {
      XDocument.UI.Alert(ex.description);
      }

       eventObj.ReturnStatus = true
     
    }

     

  • 07-08-2009 03:32 PM In reply to

    What line is the error on? This looks like it should be fine, if I compare it to this MSDN sample. As long as the XPath is right for each of the variables that you are setting with values from the form....

    Hilary Stoupa

  • 07-08-2009 04:12 PM In reply to

    • Mosel
    • Not Ranked
    • Joined on 06-25-2009
    • Posts 12

    The error occures on each and every var. I have checked the xPath and each and every line is correct.

  • 07-08-2009 04:28 PM In reply to

    I wonder if you accidentally deleted the namespace definition from the top of the script file. It looks like this (only your namespace would be different for your form):

    // The following line is created by Microsoft Office InfoPath to define the prefixes // for all the known namespaces in the main XML data file. // Any modification to the form template files made outside of InfoPath // will not be automatically updated. // XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-08T23:17:28"'); ////<namespacesDefinition>XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-08T23:17:28"');//</namespacesDefinition>

    Hilary Stoupa

  • 07-08-2009 05:11 PM In reply to

    • Mosel
    • Not Ranked
    • Joined on 06-25-2009
    • Posts 12

    The namespace definition is all there and still the same object error on the var functions


    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-07-08T23:17:28"');


    function XDocument::OnSubmitRequest(eventObj)
    {

     var urgency = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requesturgency").text;  
     var personel_last_name = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestfirstname").text;
     var personel_first_name = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestlastname").text;
     var location = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestlocation").text;
     var due = XDocument.DOM.selectSingleNode("/my:myFields/my:clientgroup/my:Requestcompletion").text;  
     
       
     var type = XDocument.DOM.selectSingleNode("/my:myFields/my:Jobtypegroup").text;
     
     
    try
      {
      var oEnvelope = XDocument.View.Window.MailEnvelope;
     
      oEnvelope.To = "Print&[email protected]";
      oEnvelope.CC = "[email protected]";
      oEnvelope.Subject = "Copy Print & Fulfillment Request - " + type + " - " + personel_last_name + ", " + personel_first_name + " - " + location + " - " + urgency + " - " + due;
      
      oEnvelope.Visible = true;
      }
     catch (ex)
      {
      XDocument.UI.Alert(ex.description);
      }

       eventObj.ReturnStatus = true
     
    }

  • 07-09-2009 09:08 AM In reply to

    I can't help but notice that in the code sample you've posted, you have exactly the same namespace as was defined in my sample. Since Infopath bases the namespace off the date and time the form was created, it seems unlikely we created our forms at exactly the same date and time.

    One way to find the namespace for your form is to save it as source files and open either template.xml or sampledata.xml in a text editor. Look for the xmlns:my attribute on the root element of my:myFields.

    Hilary Stoupa

Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.