Get the computer name to pre-populate a field on a form
-
Tuesday, April 10, 2012 8:17 PM
I have a form that asks for the computer name associated with their PC. It also asks other things, and through these two articles (and a few more), I was able to pre-populate some other fields:
- http://blogs.microsoft.co.il/blogs/itaysk/archive/2007/04/05/InfoPath-_2D00_-Get-the-current-user-without-writing-code.aspx
- http://claytoncobb.wordpress.com/2009/06/21/userprofileservice-extended/
What I'm wondering is, is there a way to pre-populate a field with the computer name of the system on which they are filling out the form?
Thanks!
All Replies
-
Tuesday, April 10, 2012 8:41 PMProbably, System.Web.HttpContext.Current.Request.UserHostName can help. It gets the DNS name of the remote host. Then you need, somewhere in codebehind, to generate and add javascript, which populates a field on the page with the host name.
.Net Follower (http://dotnetfollower.com)
-
Tuesday, April 10, 2012 9:10 PMThanks! I'll try that!
-
Wednesday, April 11, 2012 3:09 PM
I don't know javascript, and I am unfamiliar with the syntax I would use to interrogate that value. Can you point me to a resource that could help me implement this? Google searches haven't turned up anything.
Thanks!
-
Thursday, April 12, 2012 7:54 AMModerator
Hi Daddicus,
Try to use JavaCcript to dynamic assign InfoPath as following:
function XDocument::OnLoad(eventObj) { //Create a WScript.Network object, which provides access to the user data var objNetwork = new ActiveXObject("WScript.network"); //Retrieve the ComputerName and write it into the my:ComputerName field XDocument.DOM.selectSingleNode("/my:myFields/my:ComputerName").text= objNetwork.ComputerName; }NOTE: It's only can use for Internet Explorer Browser, Internet Explorer's security settings will affect whether you can create and use the WScript.Network object.
For more information, please refer to the following link:
http://blogs.msdn.com/b/timpash/archive/2005/10/17/retrieve-user-name.aspx
Thanks,
Lhan Han
- Edited by Lhan HanModerator Thursday, April 12, 2012 7:56 AM
- Marked As Answer by Lhan HanModerator Friday, April 20, 2012 1:35 AM

