Importing with Script - InfoPath Dev
in

InfoPath Dev

Importing with Script

Last post 10-03-2005 10:15 PM by Patrick Halstead. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 09-29-2005 09:41 AM

    Importing with Script

    I'm creating a template that has a script to import filenames into the document. I've been able to create a script(within Infopath) that cycles through a folder displaying the names of the files in a popup message boxs.

    Now I need to append that information into XML in the document. How the heck do I do that? Each file has its own element, and also has sub-elements like filename,path, and description.

    For Each oFile in oFSO.GetFolder(FolderName).Files
    1) Add an additional element to the end of the document.
    2) Enter in the Path and the Filename into it.
    Next

    I think this is a rather rookie question - hope someone can help



  • 09-29-2005 11:07 PM In reply to

    Hi Gumboot,
    Please read the SDK and use Import and write a custom xsl.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 09-30-2005 07:52 AM In reply to

    Hm, maybe I'm wrong, but I don't think that was the question he was asking, Patrick.

    If you're trying to populate a repeating table within your DOM (which is what it seems like you're trying to do) - try this:

    // get the list of nodes from table 1
    var h_items = xDoc.selectNodes( "/my:Proposal/my:h_items/my:h_item" );
    // get the list of nodes from table 2
    var shipTable = xDoc.selectNodes( "/my:Proposal/my:i_items/my:i_item" );
    // get the nodes to query to
    var h_itemsMstr = intDoc.selectNodes( "/pl:PriceList/pl:FSHardware" );

    // get a sample node to clone, set loop control
    var shipNode = shipTable.nextNode(); // gets a sample 'my:i_item' node
    var firstTime = true;

    while( h = h_items.nextNode() )
    {
    // ADD ROW TO SHIPPING
    var check = intDoc.selectSingleNode( "/pl:PriceList/pl:FSHardware[pl:h_shipCost != 0 and pl:h_partNum = '" + h.selectSingleNode( "my:h_prodName" ).text + "']" );

    if( firstTime )
    {
    shipTable.removeAll();
    firstTime = false;
    }

    // establish values
    var name = "Shipping for '" + check.selectSingleNode( "pl:h_name" ).text + "'";
    var qty = getNodeTypedValue( h.selectSingleNode( "my:h_qty" ) );
    var unitPrice = getNodeTypedValue( check.selectSingleNode( "pl:h_shipCost" ) );
    var extPrice = qty * unitPrice;

    // create the new row
    var newRow = shipNode.cloneNode(true);

    // populate the new row
    setNodeTypedValue( newRow.selectSingleNode("my:i_prodName"), name );
    setNodeTypedValue( newRow.selectSingleNode("my:i_qty"), qty );
    setNodeTypedValue( newRow.selectSingleNode("my:i_unitPrice"), unitPrice );
    setNodeTypedValue( newRow.selectSingleNode("my:i_extPrice"), extPrice );

    // add the new row to the list
    xDoc.selectSingleNode( "/my:Proposal/my:i_items" ).appendChild( newRow );
    }



    I know this is probably very hard to understand, but it's the best I could whip up in 5 mins. Also, I'm copying rows from one table in InfoPath to another. You could easily modify the code to copy elements from an oFile object and put them into the row. The key things you need to look at are shipTable.removeAll(), var newRow = shipNode.cloneNode(true), and xDoc.selectSingleNode( "/my:Proposal/my:i_items" ).appendChild( newRow ).

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 09-30-2005 10:38 AM In reply to

    Thanks Matt,

    I'll keep those key things in mind. This at least makes sense to me (unlike the rather cold SDK).

    I'll let you guys know how I make out.
  • 10-01-2005 12:43 AM In reply to

    The SDK isn't cold, but my response might have been. Reality is that I haven't had as much time to respond this week. Anyway, sorry about that. Nevertheless, using Merge Forms functionality ala Import will solve this problem. Matt, the Import stuff is very underappreciated but it works great. The key advantage is a) less code, and b) support for multiple kinds of forms (to be imported).

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 10-03-2005 07:34 AM In reply to

    I really need to look into the Import stuff, but how would it apply in this situation? He's creating rows with information about files in a directory within his form, that he wants to display. What would you be importing? From my understanding (which is limited), Import brings in data from an XML file and makes it available in the target form. How would you get an XML file to dynamically create rows based on files in a directory?

    Maybe you could do like a self-import? Where you import your XDocument.DOM and only read in values that you want and apply them to the table that you want them to go to?

    If I'm making no sense, sorry, just trying to understand.

    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-03-2005 10:15 PM In reply to

    Default import will add rows to a repeating section if the schema is the same. Custom import can define adding rows to the main data source's schema too. Very powerful tool that noone knows about. Good luck!

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.