Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS - InfoPath Dev
in

InfoPath Dev

Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

Last post 07-15-2009 08:23 AM by kennebg. 38 replies.
Page 2 of 3 (39 items) < Previous 1 2 3 Next >
Sort Posts: Previous Next
  • 07-10-2009 11:37 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    I've been following this post with some interest as I have been running into the same issue that kennebg references in his last post...

    I am creating a change control form.  I want users to have the ability to copy data stored in a SharePoint list into a repeating table in the main form data source and be able to edit it as necessary (changes do not need to be pushed back to the SP list).

    So far, I've defined my namespace, using the sampledata.xml file:
    <xd:DataConnection Name="SRM Customer Contacts">
      <dfs:myFields xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-23T17:07:57" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003">
       <dfs:dataFields>
        <dfs:SRM_Customer_Contacts Customer="" Full_Name="" E-mail_Address="" Business_Phone="" Home_Phone="" Mobile_Phone="" Notes="" ID=""/>
       </dfs:dataFields>
       <xd:SchemaInfo LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution">
        <xd:Namespaces>
         <xd:Namespace LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"/>
         <xd:Namespace LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"/>
         <xd:Namespace LocalName="myFields" NamespaceURI="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"/>
        </xd:Namespaces>
       </xd:SchemaInfo>
      </dfs:myFields>
     </xd:DataConnection>

    My Namespace definition is:
    XDocument.GetDOM("SRM Customer Contacts").setProperty("SelectionNamespaces",'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-06-23T17:07:57" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');

    My script is:
    function CTRL145::OnClick(eventObj)
    {
    // ensure a customer is selected
    if(XDocument.DOM.selectSingleNode("/my:myFields/my:fldCustomerName").text == "")
    {
    // Notify the user if no customer is selected
    XDocument.UI.Alert("Please select a customer before attempting to load contacts from SharePoint.");
    return;
    }

    // Get a copy of the main DOM node
    var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:group7/my:grpCustomerContacts").cloneNode(true);
    // clear the main DOM nodes
    XDocument.DOM.selectNodes("/my:myFields/my:group7/my:grpCustomerContacts").removeAll();

    // Copy nodes from 2DS to main DOM
    var nodes = XDocument.GetDOM("SRM Customer Contacts").selectNodes("/dfs:myFields/dfs:dataFields/dfs:SRM_Customer_Contacts");
    XDocument.UI.Alert(nodes.length); // this alert always returns 5 (which is the number of records on SharePoint)
    var node;
    while (node = nodes.nextNode())
    {
    var newContact = clone.cloneNode(true);
    newContact.selectSingleNode("my:fldCustContName").text = node.selectSingleNode("Full_Name").text; XDocument.DOM.selectSingleNode("/my:myFields/my:group7").appendChild(newContact);
    //XDocument.UI.Alert(node.text); //this alert is always blank
    //clone.selectSingleNode("my:fldCustContName").text = node.selectSingleNode("Full_Name").text;
    //XDocument.DOM.selectSingleNode("/my:myFields/my:group7/my:grpCustomerContacts").appendChild(clone.cloneNode(true));
    }
    }

    When I preview the form, I get the following error:
    Object required
    File:script.js
    Line:140

    Which is this line of code:
    newContact.selectSingleNode("my:fldCustContName").text = node.selectSingleNode("Full_Name").text;

    I've been trying to get this to work, off and on, for the last two weeks.  I'd really like to be able to move forward with this project, but am at this point 100% stuck.  Any help is greatly appreciated...

    kennebg -- sorry to hijack your thread.

  • 07-10-2009 12:18 PM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Just at a quick glance, I'd suggest your xpath to Full_Name is wrong:

    node.selectSingleNode("Full_Name")

    Should probably be:

    node.selectSingleNode("@Full_Name")

    Hilary Stoupa

  • 07-10-2009 12:30 PM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    That solved my problem.  Thanks Hillary!

  • 07-13-2009 07:24 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Happy Monday to all.

     So Hillary I tried your suggestion of this code:

         // Get a copy of the main DOM node.
         var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:group3/my:Test_Details").cloneNode(true);
         // Clear the main DOM nodes.
         XDocument.DOM.selectNodes("/my:myFields/my:group3/my:Test_Details").removeAll();
         // Copy nodes from 2DS to main DOM.
         var nodes = XDocument.GetDOM("GetListItemsStr").selectNodes("/dfs:myFields/dfs:dataFields/tns:GetListItemsStrResponse/tns:GetListItemsStrResult/Rows/row");
         XDocument.UI.Alert(nodes.length);
         var node;
         while(node = nodes.nextNode())
         {
              var newTestDetails = clone.cloneNode(true);
              newTestDetails.selectSingleNode("my:HuInput").text = node.selectSingleNode("Title").text;
              //newTestDetails.selectSingleNode("my:AnotherField").text = node.selectSingleNode("Status").text;
              XDocument.DOM.selectSingleNode("/my:myFields/my:group3").appendChild(newTestDetails);
         }
     
     
    The HuInput field does not get populated. I get no errors but I just get blank lines in the repeating table so the loop is working but nothing makes it to the field in the repeating table.  I'm still just working with the one field right now to get it worked out. If I try to just set a normal field on the page to the returned value then that works but I need to be able to set the value in the fields of the repeating table as they are inserted.
     
    I will continue to work with it but please let me know if you see anything wrong with this.  I did change "Title" to the name of the field I need to receive and I commented out the second line for now.
     
    Thanks!
  • 07-13-2009 09:10 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    You get blank lines? So additional lines are added? Can you verify that your secondary data connection has values for whatever field you using from the GetListItemsStr data source?

    Hilary Stoupa

  • 07-13-2009 09:34 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Yes, it populates the repeating table that I have bound directly to the secondary DBXL connection but I cannot use that repeating table because I need to be able to remove and insert other lines in the table. Also, If I direct the result to just a field on the form that is not a repeating table it populates it.  It just does not work when going into the repeating table. The lines are added to the table but they are blank.

  • 07-13-2009 09:40 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Can you reply to this post and attach your template? Look under the Options tab to find a place to add a file.

    Hilary Stoupa

  • 07-13-2009 10:02 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Here it is.  View 1 is the view i'm working in to trouble shoot this. I run the query by itself at this point using rules and then the COPY button executes the JS to attemp to copy the information from the secondary into the main.  I will be moving multiple fields once I get it working but no reason to work with more than one during the troubleshooting.

    You will see I am trying to move it into field10 instead of HuInput as I moved HuInput out of the table just to see if it would work as a standalone field and it seems to.

     Thanks!

  • 07-13-2009 10:27 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Your Xpath in your script is incorrect.

     Looking at the section you currently have commented out:

    //while(node = nodes.nextNode())
    //{
    // var newTestDetails = clone.cloneNode(true);
    // XDocument.DOM.selectSingleNode("my:field10").text = node.selectSingleNode("Test_Serial_Number").text;
    // //XDocument.DOM.selectSingleNode("/my:myFields/my:HuInput").text = node.selectSingleNode("Test_Serial_Number").text;
    // XDocument.DOM.selectSingleNode("/my:myFields/my:group3").appendChild(newTestDetails);
    //}

    You are trying to select the field you want to fill using XDocument.DOM.selectSingleNode -- you need to be selecting the node from the newTestDetails variable, however.

    Given your current data structure (never minding fields you have moved around for testing), you need something like:

    while(node = nodes.nextNode())

    {

      var newTestDetails = clone.cloneNode(true);

      newTestDetails.selectSingleNode("my:field10").text = node.selectSingleNode("Test_Serial_Number").text;

      XDocument.DOM.selectSingleNode("/my:myFields/my:group3").appendChild(newTestDetails);

    }

    Have you tried this? I note in your code in the form that is not commented out, you have a preceeding "/" to "my:field10" that needs to be removed for the node to be selected correctly as well.

    Hilary Stoupa

  • 07-13-2009 11:46 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    OK.  That worked for the first field, field 10.  So now I tried to proceed cautiously by expanding to one for more field and it's blowing up with this error: 

    '#PCDATA' is in nil content: <{http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-04-28T14:41:50}field11>.

    File:script.js
    Line:143

     

    Here's the current code:


    function CTRL188_5::OnClick(eventObj)
    {
    // Get a copy of the main DOM node.
         var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:group3/my:Test_Details").cloneNode(true);
         // Copy nodes from 2DS to main DOM.
         var nodes = XDocument.GetDOM("GetListItemsStr").selectNodes("/dfs:myFields/dfs:dataFields/ns1:GetListItemsStrResponse/ns1:GetListItemsStrResult/Rows/row");
                  
         var node;
        
         while(node = nodes.nextNode())
         {
              var newTestDetails = clone.cloneNode(true);
              newTestDetails.selectSingleNode("my:field10").text = node.selectSingleNode("Test_Serial_Number").text;
              newTestDetails.selectSingleNode("my:field11").text = node.selectSingleNode("Diameter").text;
              XDocument.DOM.selectSingleNode("/my:myFields/my:group3").appendChild(newTestDetails);
         }
     // Write your code here
    }

    What fun. The only difference I see is that in the table it is a Double Decimal field instead of a text field.  It is stored in SharePoint as a Double Decimal but I notice when I look in the DBXL secondary data source that it shows it as a string.  Do I need to change something in my DBXL query or do I have to perform some type of conversion on it from a string back to a number before trying to insert it?

    The error is occuring right at the appendChild command of the script. Not the line just above it where it gets set?

    I know I'm asking you lots of basic JS here but I'm in a bind.


     

  • 07-13-2009 11:59 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    For fields other than text, the xsi:nil attribute may be on the node -- for example, if you have a main data source element that is of a type decimal and it is NOT marked 'Cannot be blank', the xsi:nil attribute will be present. You'll need to remove it. Try looking at the script on some of the sample forms installed with InfoPath for examples. The Asset Tracker sample uses this to remove xsi:nil:

    // The xsi:nil needs to be removed before we set the value.
    if (value != "" && xmlNode.getAttribute("xsi:nil"))
    xmlNode.removeAttribute(
    "xsi:nil");

    So, for your code, maybe something like...

    var field11 = newTestDetails.selectSingleNode("my:field11");
    var diameter = node.selectSingleNode("Diameter").text;
    if (diameter != "" & field11.getAttribute("xsi:nil"));
    xmlNode.removeAttribute("xsi:nil");
    field11.text = diameter;

    I didn't test this, so there is every chance in the world I might have a typo, but hopefully that will give you the idea...

    Hilary Stoupa

  • 07-13-2009 02:05 PM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    Good grief Charlie Brown.  One step at a time!

    So with a little work I got the nil attribute to work.

    Now I have encountered a situation where there i a record but it has no Diameter input in it as of yet.  This could happen.  I have tried to test it comparing for null and undefined but neither seems to work.  I may be testing against the wrong thing.

    I've spent the better part of the afternoon trying to find the answer myself.  Basically the record has been created but that field is yet to be populated at all. It errors out with object required error when it tried to appendchild. I'm asuming that since it was not populated it just doesn't exists in the XML yet? 

     Here is the current code minus my attempts to test for null or undefined.  This works fine as long as there is a value in the Diameter field.

    function CTRL188_5::OnClick(eventObj)
    {
    // Get a copy of the main DOM node.
         var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:group3/my:Test_Details").cloneNode(true);
         // Copy nodes from 2DS to main DOM.
         var nodes = XDocument.GetDOM("GetListItemsStr").selectNodes("/dfs:myFields/dfs:dataFields/ns1:GetListItemsStrResponse/ns1:GetListItemsStrResult/Rows/row");
                  
         var node;
        
         while(node = nodes.nextNode())
         {
              var newTestDetails = clone.cloneNode(true);
              newTestDetails.selectSingleNode("my:field10").text = node.selectSingleNode("Test_Serial_Number").text;
          
        newTestDetails.selectSingleNode("my:field11").text = node.selectSingleNode("Diameter").text;
        var field11 = newTestDetails.selectSingleNode("my:field11");
        var diameter = node.selectSingleNode("Diameter").text;
        if (diameter != "" & field11.getAttribute("xsi:nil"));
        field11.removeAttribute("xsi:nil");
        field11.text = diameter;
       
        XDocument.DOM.selectSingleNode("/my:myFields/my:group3").appendChild(newTestDetails);
         }
     // Write your code here
    }

  • 07-13-2009 02:36 PM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    The field should exsist in the secondary data source -- it will just have a blank value. You should remove this line: newTestDetails.selectSingleNode("my:field11").text = node.selectSingleNode("Diameter").text; as you are setting that after you check for and remove the nil attribute. However, to test to see if a node is null,  I believe you can use null == node with node being the variable you want to test (sorry, not really a javascript girl, so I'm guessing on that one).

    Hilary Stoupa

  • 07-14-2009 07:46 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

     

    OK,  It still appears that since that field is not populated it is just not there?  It keeps giving me an object required error when I get to that point.  I tried using the null comparison but that doesn't work either.  I tried using .length and it gives me the lengths for the items up to the one without anything and then still will blow for an object required.  So it's really like it does not exist yet. 

    Can anyone tell me how to test to see if an object exists before I try to reference it which blows the script up?  I don't really want to fill the fields with blanks or zeros when the record is created because there are valid reasons that it may not yet have been filled in.  I guess I could set them all to spaces when the record is created and perhaps that would solve the problem but I would think there is more elegant way to deal with it?  Also, just in case because one could get by and I don't want it blowing up if it does.

     If someone has experienced this and knows what to do, please share with me.  I may be on the completely wrong track but since it works fine until it gets to the record where the field has not been populated and the error I get is Object Required then I am assuming it means the object doesn't exist?

     Hillary, thanks so much for all your help on this and I'm in good shape if I can learn how to test for this.

  • 07-14-2009 08:09 AM In reply to

    Re: Copy/Clone data from DBXL Secondary Data Connection to InfoPath 2003 Repeating table in Main Data in JS

    To test for whether a field is null, using the node variable declared in your while loop:

    var field = node.selectSingleNode("Diameter");

    if (null == field)
    {
       //do something
    }
    else
    {
       //do something else
    }

    Hilary Stoupa

Page 2 of 3 (39 items) < Previous 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.