Switchview before sending email - InfoPath Dev
in

InfoPath Dev

Switchview before sending email

Last post 07-30-2010 02:55 PM by AzuDaioh. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 07-22-2010 04:46 PM

    Switchview before sending email

    I'm very new to Infopath/vbscript. Please correct me if I'm wrong, I read somewhere that infopath processes the rules first before the codes but I cannot switch view before the code processed. I have an onClick button with rules and custom codes. One of the rules is to switchview to "Reminder". The code im using is to send an email using objOutlookMsg.

    But...how do I switchview first before the code is run? I placed the switchview action at the very top of my rule and I even tried using XDocument.View.SwitchView("Reminder") at the first top of the code. They dont seem to make a difference.

    We've been having trouble with Outlook so I would like the users to see the reminder first in case Outlook is down. 

    Any help is appreciated.  Thanks!!

  • 07-22-2010 06:20 PM In reply to

    Re: Switchview before sending email

    Rather than switch views before emailing (don't know how it functions with code, but if you are using rules, you'll get a blank email at best), add a section to your form's main view, and put all the controls you want in your "Reminder" view in that section. Put all the other controls in the view in another section. Add a field to your form (or a secondary data source) -- call it something like "Emailing". When the user clicks the button, set Emailing to true (or do that in your code). At the end of your code, set Emailing back to true. Conditionally format your sections so that the view you want in the email hides unless Emailing = true, and the view you want to usually show hides unless Emailing = false.

    Hilary Stoupa

  • 07-23-2010 06:22 AM In reply to

    Re: Switchview before sending email

    Another way to do it is to add a hidden field in your form named something like DefaultView with the name of your default view as the default value. Then, in the code, when the user sends the email, change the value of this field to the name of the view you want them to see. On the OnLoad event of your form, change the default view for the value in this hidden field.

    e.SetDefaultView("View 1");

    Hope that helps

  • 07-23-2010 11:10 AM In reply to

    Re: Switchview before sending email

     

    Thank you Hilary for the suggestions.  This gave me an idea for another project. But for the one I'm working on, the section appeared after I confirmed the 2 dialog boxes.

    When I click the 'submit' button, it does the following:
    1) submit the data from the form onto a list on SharePoint
    2) sends an email automatically to the appropriate people using objOutlookmsg -- but this requires 2 dialog boxes to appear, the 1st is to allow access to Outlook and the 2nd box is to confirm sending the email automatically.

    What I would like to accomplish, hopefully, is to display a view/section (Reminder) before the 2 dialog boxes appears.  I can add an action in my rule to display a dialog box with expression but I'm hoping I can display a more colorful/bigger reminder.

     Thanks again.

  • 07-23-2010 11:23 AM In reply to

    Re: Switchview before sending email

    Thank you mgarant.

    I tried this too but I'm getting an error message regarding 'e'...I think this code is for Jscript/infopath 2007? We are still using Infopath 2003 (sorry I forgot to mention in my original post). However, using this example I found something for infopath 2003 (http://support.microsoft.com/kb/826997) but the example is in jscript or was it c#. I tried converting it so vbscript. I got the defaultview to work on the OnLoad event but I can't switch it to my "reminder" view. I could be doing it wrong too. Here's what I have:

    In my Sub XDocument_OnLoad(eventObj), I have:

    Dim objDefaultView
    objDefaultView = XDocument.DOM.selectSingleNode("//my:field1")

    if objDefaultView  = false Then
       XDocument.ViewInfos("Main").IsDefault = true
    else
       XDocument.ViewInfos("Reminder").IsDefault = true
    end if

    The "field1" is a check box set to "false" by default.  

    In my OnClick button, I added:

    XDocument.DOM.selectSingleNode("//my:field1").text = "true"

    This seems to check the field1 box but it doesn't do anything.  It doesnt change the view before or after the 2 dialog boxes appeared.

     Any help or guidance is greatly appreciated. Thanks in advance.

  • 07-23-2010 11:34 AM In reply to

    Re: Switchview before sending email

    The code I gave you is C#. I don't know vb.net, but i think i know what the problem might be...

    if objDefaultView  = false Then
       XDocument.ViewInfos("Main").IsDefault = true
       XDocument.ViewInfos("Reminder").IsDefault = false // Add this line
    else
       XDocument.ViewInfos("Reminder").IsDefault = true
       XDocument.ViewInfos("Main").IsDefault = false // Add this line
    end if

     Maybe I'm wrong, but it is worth a try

  • 07-23-2010 12:21 PM In reply to

    Re: Switchview before sending email

    Hello and thanks again. I added those lines and still did the same. It didn't change view until after the 2 dialog boxes.
  • 07-23-2010 12:33 PM In reply to

    Re: Switchview before sending email

    Does it change the view AFTER the 2 dialog boxes? Or it doesn't change at all?

  • 07-23-2010 01:10 PM In reply to

    Re: Switchview before sending email

    Hello, It changed AFTER the 2 dialog boxes. Thanks ---- Edit: Sorry, the above response is inaccurate. The switch didnt take place before or after.
  • 07-23-2010 01:16 PM In reply to

    Re: Switchview before sending email

    how and when do call the 2 dialog boxes?

  • 07-23-2010 01:27 PM In reply to

    Re: Switchview before sending email

    Edit: I'm sorry, i just found out the reason why it switched to "reminder" was because I had a rule to switchview. After I removed this rule, the code above did nothing. It didnt switch to "Reminder" before or after the 2 dialog boxes. ----

    When the OnClick button is pressed. The OnClick button has rules and custom codes. The rules are used to set values in the SharePoint list based on the values on the form. Then the custom code I have the following, this is where the 2 dialog boxes appear:

    set objOutlook = CreateObject("Outlook.Application")
    set objOutlookMsg = objOutlook.CreateItem(0)

    set objOutlookRecip = .Recipients.Add(oSendTo)
    objOutlookRecip.Type = 1

    set objOutlookRecip = .Recipients.Add(oSendCC)
    objOutlookRecip.Type = 2

    .subject = "---"
    .body = "---"

    For Each objOutlookRecip In .Recipients
    objOutlookRecip.Resolve
    Next

    .send
    eventObj.ReturnStatus = true

     Thanks for helping out.

  • 07-26-2010 06:06 AM In reply to

    Re: Switchview before sending email

    Could you post the entire OnClick function? including the declaration?

  • 07-30-2010 02:55 PM In reply to

    Re: Switchview before sending email

    Sorry for the late reply. I was pulled into doing something else. On this project, I ended up displaying another view before the user clicks the submit button. It works but not exactly what I wanted to do in the first place. Here is the OnClick function:

    Sub SubmitID_OnClick(eventObj) 

    On Error Resume Next

     Dim objOutlook
     Dim objOutlookMsg
     Dim objOutlookRecip
     Dim oFormType
     Dim oLastName
     Dim oFirstName
     Dim oSendTo
     Dim oCCTo
     Dim oSPLink


     set objOutlook = CreateObject("Outlook.Application")
     set objOutlookMsg = objOutlook.CreateItem(0)

     with objOutlookMsg

      oSendTo = XDocument.DOM.selectSingleNode("//my:myFields/my:mySendTo").text
      oCCTo = XDocument.DOM.selectSingleNode("//my:myFields/my:myCCTo").text

      
      set objOutlookRecip = .Recipients.Add(oSendTo)
      objOutlookRecip.Type = 1
      
      set objOutlookRecip = .Recipients.Add(oCCTo)
      objOutlookRecip.Type = 2
      
      oFormType = XDocument.DOM.selectSingleNode("//my:myFields/my:RefType").text
      oLastName = XDocument.DOM.selectSingleNode("//my:myFields/my:BasicGp/my:ClmtLastName").text
      oFirstName = XDocument.DOM.selectSingleNode("//my:myFields/my:BasicGp/my:ClmtFirstName").text
      oSPLink = XDocument.DOM.selectSingleNode("//my:myFields/my:SPLink").text
        
      
      .subject = oFormType & " referral for: " & oLastName & ", " & oFirstName
      .body =  oSPLink  

      For Each objOutlookRecip In .Recipients
       objOutlookRecip.Resolve
      Next
      
      .send
      
      eventObj.ReturnStatus = true
      

     end with
    End Sub

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