locked
People Picker and Sending Multiple Emails RRS feed

  • Question

  • Good Morning,

    I am having an issue with sending emails to multiple people using a People Picker in InfoPath 2010. Currently, I have multiple people picker controls on my InfoPath form. Users fill out the form and select from the people pickers individuals who will receive an email notification once the form has been submitted. Once the submit button is selected, there is lots of code that is executed to perform a number of tasks before the form is selected. One of the requirements on the form was that a number of fields would be copied out to a "history" section on the form and then  the fields would be cleared. Therefore, the values in the people pickers need to be copied out to other hidden fields on the form and stored for later use. However, that is where i am experiencing my issue. No matter how many people I select from the people picker(s), it will only copy the first value/user to my hidden field instead of the complete listing of users. In my code, which I am very new to, I simply set the value of the hidden field(s) to the people picker AccountId field. I would think it would copy the entire content of the people picker control but it doesn't for some reason. Does anyone know how to modify my code or have other options of how to copy all of the users from the people picker field programmatically? I have listed one of the copy examples below for your reference.  Thanks in advance for your help.

    CODE EXAMPLE:

    xnDoc.SelectSingleNode(

    "/my:DocTrackingAndTransmittalForm/my:Hidden/my:SentToAD", ns).SetValue(xnDoc.SelectSingleNode("/my:DocTrackingAndTransmittalForm/my:secCurrent_Routing_Transmittal/my:Sent_To_Selector/pc:Person/pc:AccountId",ns).Value);
    Monday, August 15, 2011 1:13 PM

Answers

  • This field has to be acsessed one by one using indexer. While doing this you have to concat all values. Here is how to get second value:

    xnDoc.SelectSingleNode(
     "/my:DocTrackingAndTransmittalForm/my:Hidden/my:SentToAD", ns).SetValue(xnDoc.SelectSingleNode("/my:DocTrackingAndTransmittalForm/my:secCurrent_Routing_Transmittal/my:Sent_To_Selector/pc:Person[1]/pc:AccountId",ns).Value);
    

     


    http://alecpojidaev.wordpress.com
    • Marked as answer by Dan Hudnall Tuesday, September 13, 2011 5:46 PM
    Monday, August 15, 2011 1:37 PM

All replies

  • This field has to be acsessed one by one using indexer. While doing this you have to concat all values. Here is how to get second value:

    xnDoc.SelectSingleNode(
     "/my:DocTrackingAndTransmittalForm/my:Hidden/my:SentToAD", ns).SetValue(xnDoc.SelectSingleNode("/my:DocTrackingAndTransmittalForm/my:secCurrent_Routing_Transmittal/my:Sent_To_Selector/pc:Person[1]/pc:AccountId",ns).Value);
    

     


    http://alecpojidaev.wordpress.com
    • Marked as answer by Dan Hudnall Tuesday, September 13, 2011 5:46 PM
    Monday, August 15, 2011 1:37 PM
  • Alec,

    Thank you for the prompt reply. Based on your example above, I would need to loop through the control and concatenate the values. Again, I am very new to C# but would you happen to have an example of how to do that? Would I need to use a xPathNodeIterator? Any help would be great. I imagine it would be something like the following:

    string concatenatedStringValues;

    Foreach(***value in the control***) <----------what is the object that goes here

    concatenatedStringValues = concatenatedStringValues + "next value in the control"

    loop

    //after looping, I would then set the Hidden field to the concatenatedStringValue. This would need to be done for each people selector control on the form.

    Monday, August 15, 2011 1:52 PM
  • Indexer shouldn't be used together with "foreach". Just use regular "for"

    result+=xnDoc.SelectSingleNode("/my:DocTrackingAndTransmittalForm/my:secCurrent_Routing_Transmittal/my:Sent_To_Selector/pc:Person[" +i.Tostring()+"]/pc:AccountId",ns).Value;


    http://alecpojidaev.wordpress.com
    Monday, August 15, 2011 3:19 PM
  • Alec,

    Thanks again for the reply. I understand the concatenation of the result into a string but the part I don't know is the syntax for the indexer in the for loop? I have been researching and evertyhing points to using an xpathNodeIterator.

    For(**********) <---------- What would need to go here in order to create the iterator and loop through the control to the last value?

    result+=xnDoc.SelectSingleNode("/my:DocTrackingAndTransmittalForm/my:secCurrent_Routing_Transmittal/my:Sent_To_Selector/pc:Person[" +i.Tostring()+"]/pc:AccountId",ns).Value;

    loop

    Tuesday, August 16, 2011 1:56 PM
  • Alec,

    I took a look at the code and was able to come up with a suitable iterator to retrieve the AccountId names out of the People Picker control. From there, I copy the values to a hidden field on the form called Sent To AD. This field is then promoted to SharePoint when the form is published as a text field. I also created another column in the SharePoint form library called SentToAD that is of type Person/Group. I have a workflow attached to the form library that sets the SentToAD field to the results in the Sent To AD form field. I then try to send an email to the SentToAD field. However, it states that my workflow status is completed but no emails are sent. Do you know why the email might not send or what I am doing wrong. I have also placed a copy of my code snippet below. Thanks Alec.

     

     

    XPathNodeIterator sentToIterator = xnDoc.Select("/my:DocTrackingAndTransmittalForm/my:secCurrent_Routing_Transmittal/my:Sent_To_Selector/pc:Person/pc:AccountId", ns);

     

    string result="";

     

    int count = 1;

     

    foreach (XPathNavigator selectedNode in sentToIterator)

    {

     

    if (count < sentToIterator.Count)

    {

    result += selectedNode.InnerXml +

    "; ";

    count++;

    }

     

    else
     

    {

    result += selectedNode.InnerXml;

    }

    }

    xnDoc.SelectSingleNode(

    "/my:DocTrackingAndTransmittalForm/my:Hidden/my:SentToAD", ns).SetValue(result);
    Wednesday, August 17, 2011 4:38 PM
  • It's hard to say whats wrong with your workflow activity. It could be misconfigured email settings on your server or anything else. Just in case if it'll help here is link how to do it without workflow (send email from InfoPath form)
    http://alecpojidaev.wordpress.com
    Wednesday, August 17, 2011 5:00 PM