Change view based on selection in another form - InfoPath Dev
in

InfoPath Dev

Change view based on selection in another form

Last post 03-22-2011 10:30 AM by HelenW. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 03-15-2011 08:49 AM

    Change view based on selection in another form

    Hi - I am working on a set of forms that are all connected by a tabbed header (which is really a bunch of buttons).  There are 10 tabs: 1 project form with 9 work request forms.  Each work request will be associated with a project.  On the project form, each tab will show a list of associated work requests in line with the tab name (so for example, if you click on the Photography tab, you see all the photography requests associated with that project).  Once on the work request tab, you can click an edit button to edit a particular work request or create a new work request.  Both will open an existing work request form. When the Create New button is clicked, it will pass some values related to the project into the work request form, close the project form and open the work request form with that tab highlighted.  To our users, we are trying to make it look like the same form and so far I have all this working.

    The struggle comes in when I am in the work request form and want to click on any tab (button) other than the project tab.  I have setup the project button to look at the associated project and pass the values so that it opens up the correct project form.  But I'd like the work requests tabs to bring me back to the project form and open it up to the view associated with the tab(button) that was just clicked.  Here is the code that I use for the project form (and it works just fine):

      //submit the Work Request Form

    XDocument.DataAdapters["SharePoint Library Submit"].Submit();

    //set the path to the project library and form

    var LibraryPath = "http://sharepointsite/Projects%20List/";

    var FormName = XDocument.DOM.selectSingleNode("/my:myFields/my:gpIdentifiers/my:FormTitle").text;

    var FullPath = LibraryPath + FormName;

    var objXDoc; 

      //open the project form

    objXDoc = Application.XDocuments.Open(FullPath);

    //close the original form

    XDocument.View.Window.Close(true);

     

    So for instance if I'm in Work Request Type A's form and I click on the Work Request B button, I'd like it to open the project form and switch to the Work Request B view so I can see all associated work requests of type B.

    I created a field called ViewName, using the button to set the ViewName field to that of the desired view on the project form and passing that back to the project form.  I can get it to pass the ViewName in, by adding a line of code, but I cannot get it to switch views.  I tried adding an OnLoad event and that doesn't work because it passes the value after the project form has been opened and has already been loaded.  I tried using form rules and the same thing happened.

    Is there a way to do what I need to do?  I really don't want to have to create the same views on 10 forms (yeah, I could create one and then re-save it 10 times, but that still seems like a lot of extra work, especially because I have to create each work request and publish it in order to get the fields from the work request to appear on the appropriate tab, so there will come a point where re-saving will not work and I'll be editing 10 different forms the same way)  Or is there another way to approach this that I'm not thinking of?  

    Any advice/suggestions would be great.

    Thanks!

    Helen

  • 03-18-2011 06:08 AM In reply to

    Re: Change view based on selection in another form

    Anyone...?

    If this can't be done, does anyone have a suggestion of an alternate way of doing this?  

  • 03-18-2011 08:32 AM In reply to

    Re: Change view based on selection in another form

    You may need to figure out a way to set the default view of the form. Perhaps this article will help you....

    Hilary Stoupa

  • 03-18-2011 10:57 AM In reply to

    Re: Change view based on selection in another form

    Have you tried setting the view after opening the new form, see below: 

    var objXDoc; 

      //open the project form

    objXDoc = Application.XDocuments.Open(FullPath);

    objXDoc.View.SwitchView("Name of View");

    //close the original form

    XDocument.View.Window.Close(true);

     

    Or have you tried to set the view by using code with the field that has the view name in it.

  • 03-21-2011 05:39 AM In reply to

    Re: Change view based on selection in another form

    Thanks for the suggestions. 

    I found that article that Hillary referenced before I posted and wasn't sure how to translate it to work with the current code I'm using, since my code is in JScript

    I tried using objXDoc.View.SwitchView("Name of View");

    and received the following error message: 

    InfoPath cannot execute any view-related object model calls. The view is not ready.

    I did a quick search for that error message and didn't find anything that helped.  Any ideas how to tend that message?  Or another way to accomplish what I need to do?

  • 03-21-2011 07:01 AM In reply to

    Re: Change view based on selection in another form

    The error is just saying either that the objXDoc form hasn't loaded all the way when the SwitchView was called or the view wasn't active when that line of code was called.

     Is there any reason as to why you are using multiple forms instead of one form?  Just curious is all.

    If the SwitchView did not work, then unfortunately, I don't think anything will.  To switch the view like you want, the form you are switching the view of has to be the active window.

    Sorry I couldn't be of more help.

  • 03-21-2011 10:10 AM In reply to

    Re: Change view based on selection in another form

    That error was why I suggested changing the default view of the form. Did you read the script for the IP 2003 sample?

    XDocument.ViewInfos("View 1").IsDefault = true;

    Change "View 1" for the name of the view you want to use.....

    Hilary Stoupa

  • 03-22-2011 10:30 AM In reply to

    Re: Change view based on selection in another form

    Hi Hilary...I did try the sample shown in that article.  Unfortunately, that article is using the OnLoad event and I'm back where I started...it passes the value after the project form has been opened and has already been loaded.  So it doesn't work.

    @leoffneym - the reason that I need separate forms is because each work request needs to be saved into a different doclib.  If I put all the project and work request information into one doclib, it'd be super huge.  If I use one form and submit to multiple libraries, there will be multiple versions of the project information floating around on each work request's form.  

    I'm starting to think that I'm going to have to make the views in every form.  Surely there must be a better way!!! Any other ideas?


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