Set fields value with user function - InfoPath Dev Sign in | Join | Help in Newbie Questions InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Newbie Questions » Set fields value with user function 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: Oldest to newest Newest to oldest Previous Next 03-27-2007 06:23 AM stumbler Joined on 01-19-2007 Belgium Posts 49 Set fields value with user function Reply Contact 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 nukkumatti Joined on 12-08-2005 Germany Posts 349 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact 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 stumbler Joined on 01-19-2007 Belgium Posts 49 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact 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 Matt Faus Joined on 08-18-2006 Dallas, Texas Posts 1,558 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact 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 MVPQdabra® Software / Streamline data gathering to turn process into knowledge 03-28-2007 07:16 AM In reply to stumbler Joined on 01-19-2007 Belgium Posts 49 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact 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 Joined on 03-29-2007 Posts 23 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact The code lineXDocument.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 B.Shiva Prasad Joined on 01-19-2007 India Posts 102 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact 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 PrasadInfoPath Dev, http://www.ggktech.comIndia 03-29-2007 05:34 AM In reply to stumbler Joined on 01-19-2007 Belgium Posts 49 Re: Set fields value with user function Mark as Not AnswerMark as Answer... Reply Contact 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.