variables are gone after new record - InfoPath Dev
in

InfoPath Dev

variables are gone after new record

Last post 10-05-2010 01:55 PM by Desmo. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 10-05-2010 11:34 AM

    • Desmo
    • Not Ranked
    • Joined on 09-17-2009
    • Posts 14

    variables are gone after new record

    Hello everyone,  this forum has always been so helpful, I'm hoping you guys can help me solve one more.  

     Utilizing infopath 2003 (yes, large corporations tend to lag behind on upgrades) I have inserted a get login username code based off of a prior posting which works great.

    var wshShell = new ActiveXObject("Wscript.Shell");
    var wshEnv = wshShell.Environment("Process");
    var username = wshEnv.Item("UserName");
    XDocument.DOM.selectSingleNode("dfs:myFields/my:Relayview").text= username;  

     I've relayed this value to personal fields that build logic off of one another to derive the group and dept. ID as well.   

     The form itself is a time tracking form, where users log their projects. Its great that it can self identify who the user is, but here's the issue.

     As soon as the "new record" button is clicked, Vuwala,  everything is wiped out and all my concatenated fields that rely on the username variable are reduced to junk.   Using a refresh button doesn't work bc it only refreshes the data connection.  The only option I can see at this point is that I have the form close and re-open, but that will look terrible.

     does anyone know of any work arounds?   It seems I just need to refresh the scripts and webservice for the username isn't an option either b/c I have no idea what the correct adpx addresses are.

     Thanks in advance!!


     

  • 10-05-2010 12:18 PM In reply to

    Re: variables are gone after new record

    Hi Desmo and thanks for the positive comments! :)

    You have discovered one of the limits of Database bound forms - the default functionality of the database binding overrides some of the functionality of InfoPath. If you had instead started from a Blank form and added XML fields to your schema (instead of binding to a Database), you could easily do this by adding a button with two rules - 1) query Database/Web Service, 2) set values from database into main data source (or just drag and drop the secondary data source into your view) and finally, 3) set the username value. While starting from blank gives you more flexibility, it does mean you have to hook up the Database or Web Service to pull and push data to your backend, but that's not hard to do and the gained flexibility is much more valuable.

    With your Database backed form, you still have lots of options. You can add an event that you catch after the New Record button is clicked and you can set the username again on this event. What event is your code currently hooked up to?

    More after your reply,

    Patrick Halstead
    Project Manager at Qdabra
  • 10-05-2010 01:11 PM In reply to

    • Desmo
    • Not Ranked
    • Joined on 09-17-2009
    • Posts 14

    Re: variables are gone after new record

    Thanks for the quick Reply Patrick, it didn't dawn on me that it would have made much a difference to start w/ a blank form vs creating from a database. So in that reality, this issue would not occur? If I can muster the motivation, I might give that a shot and thanks for the tip!

    This form loads on a view that displays a repeating section where all records of time entries are displayed as seen below. The New Record button is as self described, and loads to the default view, (new record section).  The submit button just submits, calls a blank id value, and queries back to the original page. so not much underlying code there.  It doesn't seem to help if I add the following to the submit button onclick event.   Relayview is the name of the myfield that holds the user name

    XDocument.DOM.selectSingleNode("dfs:myFields/my:Relayview").text= username;     

     


     

     

  • 10-05-2010 01:54 PM In reply to

    Re: variables are gone after new record

    Too bad InfoPath doesn't let you add New Record as an action to a rule since then you could set the value after that as a separate rule/action.

    Have you tried to set a default value for Relayview? Just go to the data source and double click it and click on the Fx for the default value and add XdExtension::<yourfunction name>. In 2007/10 this is easy because there's a username function that InfoPath uses. A better option might be to call a SharePoint GetUserProfileName or Active Directory Web Service (such as Qdabra's) that doens't require code.

    Patrick Halstead
    Project Manager at Qdabra
  • 10-05-2010 01:55 PM In reply to

    • Desmo
    • Not Ranked
    • Joined on 09-17-2009
    • Posts 14

    Re: variables are gone after new record

     



     

    NEvermind Patrick, I'm very happy now as I did some investigating w/ existing corporate infopath forms and discovered there's a webservice for getting the employee profile! I'm golden, thanks again
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.