Inserting Login username into text field - InfoPath Dev
in

InfoPath Dev

Inserting Login username into text field

Last post 03-10-2007 02:25 AM by jacobus.vorster. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 04-25-2006 02:43 PM

    • nwillis
    • Not Ranked
    • Joined on 04-05-2006
    • USA
    • Posts 9

    Inserting Login username into text field

    I'm very new to InfoPath and I have seen many items about how to do this. We've gotten it to work doing a MS Lab by referencing the path ("/my:myFields/my:RequestedBy). However the actual data connection that has been set up has a different structure and I've tried all sorts of combinations for the path thinking one would work. When you look at the data source it has myFields/dataFields/d:PIRRequest/:RequestedBy. I'm not sure what the d: means. I'm inserting the following script into my form and am unable to get it to work - Can anyone provide any help??:

    *****************************************************
    function XDocument::OnLoad(eventObj)
    {
    //Create a WScript.Network object, which provides access to the user data
    var objNetwork = new ActiveXObject("WScript.network");

    //Retrieve the UserName and write it into the my:RequestedBy field
    XDocument.DOM.selectSingleNode("/my:myFields/my:dataFields/my:PIRRequest/my:RequestedBy").text =
    objNetwork.UserName;
    }
    **************************************************
  • 04-26-2006 12:11 AM In reply to

    • uma
    • Top 500 Contributor
    • Joined on 12-23-2005
    • Posts 35

    Re: Inserting Login username into text field

    Hi,

    In the InfoPath while mentioning the XPath for a field you have to give the xpath correctly by mentioning the correct name spaces. And "my" is not the namespace for all the fields, some times it is different depending on the name space setting.

    I can't give the correct xpath by seeing the details which u mentioned, but, one way to solve your problem is, open the template.xml file in the text editor Or in the visiual studio editor and see for the namespace of the each and every field. And replace the “my”(in the xpath which you mentioned above) with the correct namespace which you find in the template.xml file.

    Hope, this will help you to solve your problem.
  • 04-26-2006 12:20 PM In reply to

    • nwillis
    • Not Ranked
    • Joined on 04-05-2006
    • USA
    • Posts 9

    Re: Inserting Login username into text field

    Thank you, now it is working perfectly!
  • 05-01-2006 09:07 AM In reply to

    • nwillis
    • Not Ranked
    • Joined on 04-05-2006
    • USA
    • Posts 9

    Re: Inserting Login username into text field

    I can get the user id to prepopulate just fine with the code below. Now of course I need to use a recognizable name such as John Smith rather than user id jsmith. Plus I need to pull in the users department name and phone number, email etc. When I tried to replace "UserName" with "displayName" below (as what I see being the attribute in AD....it doesn't work. As well as if I add another line under username with department....doesn't work. Is this possible to do and how?

    *****************************************************************
    function XDocument::OnLoad(eventObj)
    {
    //Only load data if the fields are empty.
    if (XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:PIRRequest/@RequestedBy").text == "" )

    //Create a WScript.Network object, which provides access to the user data
    var objNetwork = new ActiveXObject("WScript.network");

    //Retrieve the UserName and write it into the my:RequestedBy field
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:PIRRequest/@RequestedBy").text =
    objNetwork.UserName;
    }
  • 05-01-2006 11:11 PM In reply to

    • uma
    • Top 500 Contributor
    • Joined on 12-23-2005
    • Posts 35

    Re: Inserting Login username into text field

    Yes, you can do the things like populating the data(display name, dept name, phone number, email ID) based on selected data(User Name) using secondary data source connection. For the details see the given link.

    http://infopathdev.com/howto/tutorials/default.aspx?i=9111ef580f95479890fc18fb2c5bac85

    I hope, it is what you want..
  • 05-02-2006 01:13 PM In reply to

    • nwillis
    • Not Ranked
    • Joined on 04-05-2006
    • USA
    • Posts 9

    Re: Inserting Login username into text field

    I was meaning to populate text fields with Display Name, department, phone number (Active Directory attributes).
  • 05-11-2006 05:55 AM In reply to

    Re: Inserting Login username into text field

    Hi!
    Did you solve the problem with showing the displayname in a field? I have exactly the same problem as you, i get the username, but dont know get the displayname to show.
  • 05-11-2006 06:12 AM In reply to

    • nwillis
    • Not Ranked
    • Joined on 04-05-2006
    • USA
    • Posts 9

    Re: Inserting Login username into text field

    No, unfortunately I haven't been able to get anything else to work. I even had an experienced programmer work on an Active Directory web service yesterday and he couldn't get anything to work either. Not surprising - because with this product it seems everything I've tried to do has been challenging. I have one more thing to try - I'll let you know how it turns out.
  • 05-12-2006 07:00 AM In reply to

    Re: Inserting Login username into text field

    Hey guys take a look here, I think this should help you out or at least point you to the right direction.

    http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=2328

    Cheers it's weekend now !
    Listen to Motörhead cos they play Rock'n Roll :)
  • 05-12-2006 01:09 PM In reply to

    • nwillis
    • Not Ranked
    • Joined on 04-05-2006
    • USA
    • Posts 9

    Re: Inserting Login username into text field

    Mary_l - I was able to get this done and working finally. It is a "round about" solution but it works. 1) We currently have a view in the Sharepoint db (_PROF)that gathers the necessary information that AD shares with this db, ie. Preferred Name, Department, Phone, etc.... this is used as a secondary data source in the form. 2) I then created a view in our Sharepoint database (_SITE) that joins Sites and UserInfo - and am using this as a secondary data source in InfoPath as well - I needed this view because capitalization was not consistent in the first view I mentioned. 3)I added 3 fields to my SQL db and converted the main data source to include these in the form - Domain, UserId, and DomainUserId. 4) Dropped the new fields as text boxes on the form and used conditional formatting to hide them when they are not blank. 5) I used the following jscript behind the form:

    //******************************************************************
    function XDocument::OnLoad(eventObj)
    {
    //Only load data if the fields are empty.
    if (XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:PIRRequest/@RequestedBy").text == "" )

    //Create a WScript.Network object, which provides access to user data
    var objNetwork = new ActiveXObject("WScript.network");

    //Retrieve the Domain & UserName and write into Domain & UserId fields
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:PIRRequest/@Domain").text =
    objNetwork.UserDomain;
    XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:PIRRequest/@UserId").text =
    objNetwork.UserName;
    }
    //******************************************************************

    6) Created a rule in the UserId field to set the DomainUserId text field value - a value that concatenates Domain and User Id text field values (concat(@Domain, "\", .).
    7) Created a rule in the DomainUserId field that set the value of the RequestedBy (where I wanted a full name) text field to - function - @tp_Title[@tp_Login = @DomainUserId]
    @tp_Title (ex: Smith, Natalie) from the sharepoint view
    @tp_Login (ex: Domain\nsmith) from the sharepoint view
    @DomainUserId will have the concatenated version (Domain\nsmith)
    8) Created rules in the DomainUserId field that set the values of RequestorDept and Phone text fields as well.
    functions - @Dept[@PreferredName = @RequestedBy]
    functions - @Phone[@PreferredName = @RequestedBy]
    @Phone, @PreferredName, and @Dept from the other sharepoint view w/ AD information

    Like I said "round about" way to the solution....but it was all I could get to work especially with my limited knowledge of coding and limited timeframe! Part of the process (like the concatenation part) could have been shortened if I could have included this vbscript:
    *****************************************************************
    Sub XDocument_OnLoad(eventObj)
    Set oWshNet = CreateObject("WScript.Network")
    sDomain = oWshNet.UserDomain
    sUserName = oWshNet.UserName

    Set objField1 = XDocument.DOM.selectSingleNode("/my:myFields/my:fieldName")
    objField1.text = sDomain & "\" & sUserName
    End Sub
    ****************************************************************

    However, my form was already locked into jscript and I wasn't even trying to figure that one out!

    If you need any clarification, let me know. Thanks.



  • 03-09-2007 03:00 AM In reply to

    Re: Inserting Login username into text field

    Hi,

    I want to get the username of the logged in user, but when I run the code the following code I get this error message: Automation server can't create object
    -------------------------------------------------------------------------------
    function XDocument::OnLoad(eventObj)
    {
    //Create a WScript.Network object, which provides access to the user data
    var objNetwork = new ActiveXObject("WScript.network");

    //Retrieve the UserName and write it into the my:RequestedBy field
    XDocument.DOM.selectSingleNode("/my:myFields/my:dataFields/my:PIRRequest/my:RequestedBy").text =
    objNetwork.UserName;
    }
    -------------------------------------------------------------------------
    Any help will be greatly appriciated:)
  • 03-09-2007 01:31 PM In reply to

    Re: Inserting Login username into text field

    Hi Cobus,
    Are you running InfoPath 2007 or InfoPath 2003?
    Patrick Halstead
    Project Manager at Qdabra
  • 03-10-2007 02:25 AM In reply to

    Re: Inserting Login username into text field

    Hi Patrick,

    InfoPath 2003.

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