Set fields value with user function - InfoPath Dev
in

InfoPath Dev

Set fields value with user function

Last post 03-29-2007 05:34 AM by stumbler. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 03-27-2007 06:23 AM

    Set fields value with user function

    Hello,

    Is it possible to set a fields value with a user definied function?
    I have a function to get the users login name (Called: GetUserName). I would like to pass that to a field in my form. The function resides in my form code.

    How can this be done?
    Hans.
    Infopath 2003 / Jscript
  • 03-27-2007 06:34 AM In reply to

    Re: Set fields value with user function

    okay let's say you have a textbox control on your form named field1.

    Now go to tools - programming - and select OnLoad event in the menu bar.

    Now you can use:
    XDocument.Dom.SelectSingleNode("my:myField/my:field1").text = System.Environment.Username;
    Listen to Motörhead cos they play Rock'n Roll :)
  • 03-27-2007 07:03 AM In reply to

    Re: Set fields value with user function

    Sorry for my incomplete mail but I work with Infopath2003 and I am using Jscript.
    The code you suggest I guess is for VBscript is it not? anyhow, I get an error 'system not defined'
    I like to fill in the information only when they click the 'approve' button so I hoped I could enter a user function in the 'rules' part of the control.

    Hans.
    Infopath 2003 / Jscript
  • 03-27-2007 08:59 PM In reply to

    Re: Set fields value with user function

    Hi Hans, That code is indeed for JScript, you just need to capitalize DOM. The only way I can think of how to do this with rules is with our Active Directory web service. Assuming you have AD, you can issue a GetMyInfo call and it will download all info about the current user into a secondary DOM in your form. Once this is done, you can simply copy the correct field from the 2DS into the Main DOM. Here's the link if you want to check it out: http://www.qdabra.com/en/products/ADWebService.aspx
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 03-28-2007 07:16 AM In reply to

    Re: Set fields value with user function

    I tried with 'XDocument.DOM.SelectSingleNode("my:myField/my:field1").text = System.Environment.Username' and get the errormessage: 'system not defined'
    :(
    Hans.
    Infopath 2003 / Jscript
  • 03-28-2007 11:54 PM In reply to

    • chang
    • Not Ranked
    • Joined on 03-29-2007
    • Posts 23

    Re: Set fields value with user function

    The code line

    XDocument.DOM.SelectSingleNode("my:myField/my:field1").text = System.Environment.Username;

    is mixing 2 programming languages together with each other. System.Environment.Username is .NET code, not JScript, so unfortunately it will not work.
  • 03-29-2007 05:18 AM In reply to

    Re: Set fields value with user function

    Hi stumbler,

    if in jscript try this, its working.

    var oNet = new ActiveXObject("Wscript.Network");
    XDocument.DOM.SelectSingleNode("my:myField/my:field1") = oNet.UserName;
    B.Shiva Prasad
    InfoPath Dev,
    http://www.ggktech.com
    India
  • 03-29-2007 05:34 AM In reply to

    Re: Set fields value with user function

    Thanks all,

    Shiva, I used your suggestion an got it to work.
    Anyhow I find it a pity it is so hard to get AD information into infopath with jscript. On the Web you can find dozens of snippets to address this info through VBscripting. But nothing for jscript.
    Hans.
    Infopath 2003 / Jscript
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.