Add field contents to subject of email when submitting - InfoPath Dev
in

InfoPath Dev

Add field contents to subject of email when submitting

Last post 09-23-2008 12:49 PM by geolex1. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 09-22-2008 02:24 PM

    Add field contents to subject of email when submitting

    Hi All -- Thanks in advance for your help. I'm an extreme newbie.

    I am using the code from the Issue Tracking (detailed) sample form to submit the form as an email (in the body) rather than an attachment. Everything is working great, but I want the subject line to populate with some data from a particular field. Unfortunately I am not a code writer, so I came here for help. I've copied the relevant part of the code below. You can see where I've put in the standard text that I always want to appear ("Reduce and Pay Notification for TA:"), but after this I want it to populate from field TA (a text field) in the form.

    Could someone please tell me how to write this?

    Thanks!

    Geoff

    oEnvelope.To = rgRecipients.join("; ");
    oEnvelope.Subject = ("Reduce and Pay Notification for TA:");
    oEnvelope.Visible = true;

  • 09-23-2008 03:06 AM In reply to

    Re: Add field contents to subject of email when submitting

    Hi Geolex,

      can you please change your code as below inorder to get the value present in text box, and appending the text box value into the email subject.

    string textBoxXPath ; // please set the text box xpath into this variable textBoxXPath.

    oEnvelope.To = rgRecipients.join("; ");
    oEnvelope.Subject = string.Format("Reduce and Pay Notification for TA: {0}", GetNodeValue(textBoxXPath));
    oEnvelope.Visible = true;


    and add the below function into your code inorder to get the value in

    public string GetNodeValue(string xPath)
    {
     IXMLDOMNode node =  thisXDocument.Dom.selectSingleNode(xPath);
     return node.text;
    }

    Chandrakanth/GGKTech
  • 09-23-2008 08:41 AM In reply to

    Re: Add field contents to subject of email when submitting

    I sent you an email but am going to post a reply here in case anyone else can help. I'm still having a lot of trouble. I tried changing the code as you said above, but keep getting errors like, "Expected ')'    File:script.js   Line:82    oEnvelope.Subject = string.Format("Reduce and Pay Notification for TA: {0}", GetNodeValue(my:TA)); " when I try to preview the form.

    Like I said, I'm an EXTREME newbie and am not a code writer. My boss is asking for this and won't let the issue go. That's what happens, I guess, when you can make simple forms! Anyway, I posted the entire code of my document at http://home.comcast.net/~geolex1/TAEmailCode.txt. If anyone could take a look and let me know how I need to change it/where to insert the codes above I would really appreciate it. Also, I believe the xpath for the field I want is my:TA. I don't know anything about xpath either, but from what I can gather, my:TA is it.

    Thanks!!


     

  • 09-23-2008 09:22 AM In reply to

    Re: Add field contents to subject of email when submitting

    Hi --

    A couple of things:

    1. Your XPath should go in quotes in your code, like this "my:TA"
    2. Your XPath is probably wrong, since most likely it is at least in a group like myFields, so "my:myFields/my:TA"
    3. If you are using IP 2007, you can right click on the node in the data source task pane and select Copy XPath to get the XPath to the node

    If you don't have IP 2007, post a screen shot to of your data source, and I can help you with your XPath.

    Hilary Stoupa

  • 09-23-2008 10:12 AM In reply to

    Re: Add field contents to subject of email when submitting

    Hi Hilary -- thanks for your help! I have posted a screenshot of the data source at http://home.comcast.net/~geolex1/datasource.jpg.

  • 09-23-2008 10:37 AM In reply to

    Re: Add field contents to subject of email when submitting

    Is the form based off another schema or a DB? I ask because I see that TA uses the "my" namespace, but I'm not sure what namespace issue uses.

    You could try "dfs:issue/my:TA" if you are based off a DB....Or, you could save your form as source files (I think in IP 2003, it is under the File Menu, Extract form files) and look at template.xml to see the namespace for issue.

    Hilary Stoupa

  • 09-23-2008 10:56 AM In reply to

    Re: Add field contents to subject of email when submitting

    I used one of the sample forms because it had the code to put the form into the body of an email rather than an attachment. That's where all the other elements in the data source come from. I extracted the source files and opened the template.xml file. Issue uses the namespace iss. So that would make my xpath "iss:issue/my:TA" ?? Or, since it is under the contributors folder, is it "iss:issue/iss:contributors/my:TA" ?

    Now that I have the xpath figured out, I assume the code I will use (based on the first reply) will be:

    oEnvelope.To = rgRecipients.join("; ");
    oEnvelope.Subject = string.Format("Reduce and Pay Notification for TA: {0}", GetNodeValue("iss:issue/my:TA"));
    oEnvelope.Visible = true;

    Question now is, where do I put the other lines he gave me (see below)?

    string textBoxXPath ; // please set the text box xpath into this variable textBoxXPath.       and

    public string GetNodeValue(string xPath)
    {
     IXMLDOMNode node =  thisXDocument.Dom.selectSingleNode(xPath);
     return node.text;
    }

  • 09-23-2008 11:10 AM In reply to

    Re: Add field contents to subject of email when submitting

    When I look at the snap of your data source, "my:TA" doesn't appear to be inside any groups. The contributors folder is not expanded, but I can see "my:TA". This would lead me to believe that "iss:issue/my:TA" would be the correct XPath.

    You can delete the line for string textBoxXpath, if you like. The suggestion was that you set that variable to the value of the XPath to your field, but you are using the value directly in the GetNodeValue function. However, the GetNodeValue function is written in C# for IP 2007, and you are using jscript. You already have a function in your code that you can use, though: function getNodeValue(xpath, defaultValue)

    Try replacing GetNodeValue("iss:issue/my:TA") with getNodeValue("iss:issue/my:TA") and don't add the method GetNodeValue to your script, as it won't work for you.

    Hilary Stoupa

  • 09-23-2008 11:28 AM In reply to

    Re: Add field contents to subject of email when submitting

    I think we're getting close! I followed your suggestions and when I preview the form I do not get any more debug errors. However, when I click the submit button at the bottom, I get an error message saying "string is undefined." Is this coming from the line below?

    oEnvelope.Subject = string.Format("Reduce and Pay Notification for TA: {0}", getNodeValue("iss:issue/my:TA"));

    If so, how do I fix it? Or is string.Format also for use with IP 2007 not 2003?

  • 09-23-2008 11:40 AM In reply to

    Re: Add field contents to subject of email when submitting

    Try this: oEnvelope.Subject = "Reduce and Pay Notification for TA: " + getNodeValue("iss:issue/my:TA");

    Hilary Stoupa

  • 09-23-2008 12:49 PM In reply to

    Re: Add field contents to subject of email when submitting

    It worked!! Thank you so much. I appreciate your help more than you know. :)

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