Set the value of a field to a view name - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Set the value of a field to a view name

Last post 06-23-2008 07:18 AM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-22-2008 03:51 AM

    • stuck
    • Top 150 Contributor
    • Joined on 03-26-2008
    • Posts 74

    Set the value of a field to a view name

    Hi,

    how can I set a fields value to the name of the active view?

    so basically everytime a view is opened, I want a field to inherit the view name as its value.

    Thanks

  • 05-22-2008 07:34 AM In reply to

    Re: Set the value of a field to a view name

    I do not think there is a way.

    I do this frequently but set the filed to the default view name. And then on every button where the view is changed also update the field. You cnanot let them switch from the toolbar but that is rarely a requirement anyway.

  • 06-12-2008 09:08 AM In reply to

    • stuck
    • Top 150 Contributor
    • Joined on 03-26-2008
    • Posts 74

    Re: Set the value of a field to a view name

    none of my views have any buttons that changes the view. The view changing bit is taken care of anohter software that is embeded in our wss....

    I've been stuck on this for a long time now..

  • 06-20-2008 08:19 PM In reply to

    Re: Set the value of a field to a view name

    Hi:

    Are you comfortable using code for this? In IP 2007, you can add the following to the View Switched event (C#):

          string xpath = "/my:myFields/my:field1";
          XPathNavigator field = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);
          field.SetValue(
    this.CurrentView.ViewInfo.Name);

    With the string for the variable xpath set to the node you want the value of the view in. I don't know what effect (if any) the other software you are running will have -- I would imagine that the View Switched event will be called  whether the view is changed by a user or by an application.

    Hilary Stoupa

  • 06-23-2008 02:26 AM In reply to

    • stuck
    • Top 150 Contributor
    • Joined on 03-26-2008
    • Posts 74

    Re: Set the value of a field to a view name

    thanks, does that code go in the function XDocument::OnSwitchView(eventObj) bit?

    All I'm really trying to do is force mandatory fields on my views.

  • 06-23-2008 07:18 AM In reply to

    Re: Set the value of a field to a view name

    The code in my first post is C#. The function you have mentioned is jscript. For jscript, the code would be:

    var viewName = XDocument.View.Name;
    var field = XDocument.DOM.selectSingleNode("/my:myFields/my:field1");
    field.text = viewName;

    This can go in your switch view event and will display the name of the view in field 1.

    Hilary Stoupa

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