Adding Username to a field - InfoPath Dev
in

InfoPath Dev

Adding Username to a field

Last post 03-16-2007 03:32 AM by nukkumatti. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-16-2007 01:06 AM

    Adding Username to a field

    Hello,

    I made up an approval form that gets the username from the environment to put in the approriate field.
    But sometimes a request needs 2 approvals, so I put the approvals in a repeating table.
    But now, only the first record recieves the correct info. the second one always stays blank. I suppose it has to see with the use of current() but I would appriciate some help on this, since I don't know how to use it in this matter

    Here is the code I use:

    function msoxd__LOCALSALES_APPROVALS_EmployeeID_attr::OnAfterChange(eventObj)
    {
    //Create a WScript.Network object, which provides access to the user data
    var objNetwork = new ActiveXObject("WScript.network");
    var ApprName =objNetwork.UserName;
    var RealApprover = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:LOCALSALES/d:LOCALSALES_APPROVALS/@LoginID")
    RealApprover.text = ApprName

    if (eventObj.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }
    }


    Kind Regards
    Hans.
    Infopath 2003 / Jscript
  • 03-16-2007 02:55 AM In reply to

    Re: Adding Username to a field

    Hi,

    you can actually create new repeating tables dynamically (so implement the "Insert Item" function:
    Below is the code example, but take care it's in C# so you have to convert it to your JScript:

    Use this to create a new repeating section (Result is the name of the repeating section)


    //generate as many sections as you need approvals
    for(int i = 1; i < yourUserName/ApprovalCount; i++)
    {
    //create as many repeating sections as you have approvers
    string myRepeat = thisXDocument.DOM.selectSingleNode("my:myFields/my:Result/my:Results").xml;
    IXMLDOMDocument oXml = thisXDocument.CreateDOM();
    oXml.async = false;
    oXml.loadXML(myRepeat);
    IXMLDOMNode parentNode = thisXDocument.DOM.selectSingleNode("my:myFields/my:Result");
    parentNode.appendChild(oXml.documentElement);
    }


    Now you just need to fill the controls within you repeating sections:


    for(int j = 1; j <= yourUserName/ApprovalCount; j++)
    {
    thisXDocument.DOM.selectSingleNode("my:myFields/my:Result/my:Results[" + j + "]/my:YourApprovalTextBoxWithinYourRepeatingSection").text= thisXDocument.Dom.SelectSingleNode("my:myFields/my:YourApproverNameTextBox").text;
    }


    Does it make any sense to you in your case ?
    Listen to Motörhead cos they play Rock'n Roll :)
  • 03-16-2007 03:02 AM In reply to

    Re: Adding Username to a field

    Thanks for the reply,
    but I will need some time to understand your suggestion and do the conversion.
    Anyhow, I have a whole weekend ahead to figure out what is all about.

    Hans.
    Infopath 2003 / Jscript
  • 03-16-2007 03:32 AM In reply to

    Re: Adding Username to a field

    Hi again,
    here may be a small explanation.

    With the first "for" statement you can create new repeating sections.
    Put a repeating section (name Result for top node and Results for repeating node) to your form and add one textbox control to it.
    Put a button to your form and copy the code (after conversion though) into your onClick event of the Button.
    Then change yourUserName-ApprovalCount to the number 4 within your the for statement.
    Preview your form and click the button, then it should actually generate 3 additional section including a textbox control. Each of this repeating section has an index or lets call it position starting from 1 i think.

    The second "for" statment now is used to fill data into the textbox control within your repeating section.
    So this means nothing more then iterating through your sections.
    thisXDocument.DOM.selectSingleNode("my:myFields/my:Result/my:Results[" + j + "]/my:nameOfTextBoxControlWithinYourSection")


    The "j" is actually the position or index of your repeating section so if this value is 3 for example you will wirte a value into the textbox control of your third section.

    Does this help you understanding it a bit better ?
    Listen to Motörhead cos they play Rock'n Roll :)
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.