[solved] Switch view so email displays 'custom view' then switch back after send [solved] - InfoPath Dev
in

InfoPath Dev

[solved] Switch view so email displays 'custom view' then switch back after send [solved]

Last post 11-17-2014 12:09 AM by Patrick Halstead. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 06-05-2014 01:47 AM

    • Skarn
    • Top 50 Contributor
      Male
    • Joined on 04-20-2008
    • Australia
    • Posts 198

    [solved] Switch view so email displays 'custom view' then switch back after send [solved]

    You may be aware of the 'switch view before email, then email is blank' issue.
    You may also know of issues trying to switch views then switch back again - this method could help with that too.
    If you *must* have this sort of feature, I give you a template and code work around - it's not a 'simple' solution, but it does work, and quite flawlessly from what I can determine.

    There's possibly ways to refine this, but most importantly - proof of concept!
    Attached is a minimal template, and code seperately - please do what you know you have to - design mode, copy in the code, republish etc.

    Summary of method:

    • Button to submit - runs code in event
    • Code sets a global variable with a 'command' for the 'View change event' to use.
    • Code sets form field - contextTrap - to current View's name (for returning to later)
    • Code switches view to the one wanted to display in email
    • View change event picks up the change
    • View change code checks the 'command' and performs function - in this case, email submit
    • View change code sets the 'command' back to empty string (so we don't run the command again during the switch back)

    Here's the trick - normally we've tried to switch the View immediately back in the same 'code path' - but Infopath won't let us switch views BEFORE the last view change has rendered and the last 'View change event' has finished.

    By putting a text box control, bound to the my:contextTrap field AT THE VERY TOP of the 'Email Print View', AFTER the first view change event completes Infopath sets focus to this control as the first one in the view. We take advantage of that and:

    • FormEvents_ContextChanged event fires
    • Code checks if it's the 'my:contextTrap' field
    • Code reads the value of my:contextTrap to get the name of the view to return to
    • Code switches view back to the previous one
    • Code sets my:contextTrap to empty string (ready for next time)

    Infopath lets us do this now because the last view completed its render and the last view change event completed.
    Of course, the view change event fires again, but we have checks to make sure there are no infinite loops.

    Sorry if this has come up as a method before, but as far as I know, this is the first time a solution has been presented.
    If you can do this better - please tell us/me how.

    Skarn.

     

  • 11-13-2014 12:21 PM In reply to

    Re: [solved] Switch view so email displays 'custom view' then switch back after send [solved]

    Where do I insert this code in order to make it work?  I want a user to submit the form to a group via email and that form switch views so the recipient of the email sees only the correct view.  Thanks in advance!

  • 11-17-2014 12:09 AM In reply to

    Re: [solved] Switch view so email displays 'custom view' then switch back after send [solved]

    Hi AmberArcher77!

    Welcome and thank you for posting.

    You are replying to an old thread. We don't have intel about Skarn's methodology, but we would be happy to help you.

    Please email support (at) qdabra (dot) com if you would like to figure this out.

    Thanks,

    P

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.