Programatically copy Sharepoint list into Main data source - not copying data - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Programatically copy Sharepoint list into Main data source - not copying data

Last post 06-30-2010 04:08 AM by bijayani. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 04-14-2010 02:11 PM

    • vriyer
    • Not Ranked
    • Joined on 04-14-2010
    • Posts 6

    Programatically copy Sharepoint list into Main data source - not copying data

    I am trying to copy a sharepoint list data into Main data source... Here is the script I have - the problem is it is not going inside the While loop for the insertion process.. Any help is appreciated

    function CTRL79_5::OnClick(eventObj)

    {

    XDocument.UI.Alert("Begin Code");

    var extlist =XDocument.GetDOM("PhaseMetrics").selectNodes("/Phase_Metrics");

    XDocument.UI.Alert("After the first list");

    // If nothing was found, then return; there will be no items to insert.

    if(extlist == null)

    {

    XDocument.UI.Alert("Nothing was returned");

    return;

    }

    XDocument.UI.Alert("Before the Insertion point");

     

    // Get the Metrics insertion point.

    var metricList = XDocument.DOM.selectSingleNode("/my:myFields/my:Financial/my:Fin_Phase_Metrics");

     

    XDocument.UI.Alert("After the Insertion point");

    // Add the rows to the main DOM.

    var metric;

    XDocument.UI.Alert("Before the Loop");

    while(metric = extlist.nextNode())

    {

    try

    {

    // Get this Phase Metrics values from the secondary DOM.

    XDocument.UI.Alert("Inside the loop");

    var bcws = metric.selectSingleNode("@BCWS").text;

    var bcwp = metric.selectSingleNode("@BCWP").text;

    var acwp = metric.selectSingleNode("@ACWP").text;

    var name = metric.selectSingleNode("@Name").text;

    var start = metric.selectSingleNode("@Start").text;var finish = metric.selectSingleNode("@Finish").text;

     

    // Build a string representing a main DOM nodeset using the values from the secondary DOM.

    var metricXml = "<my:Fin_Phase_Metrics xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-03T00:09:57'>"

    + "<my:Fin_Phase_BCWS>" + bcws + "</my:Fin_Phase_BCWS>"

    + "<my:Fin_Phase_BCWP>" + bcwp + "</my:Fin_Phase_BCWP>"

    + "<my:Fin_Phase_ACWP>" + acwp + "</my:Fin_Phase_ACWP>"

    + "<my:Fin_Phase_Name>" + name + "</my:Fin_Phase_Name>"

    + "<my:Fin_Phase_Start>" + start + "</my:Fin_Phase_Start>"

    + "<my:Fin_Phase_Finish>" + finish + "</my:Fin_Phase_Finish>";

     

    XDocument.UI.Alert("After the XML Line");

    metricXml += "</my:Fin_Phase_Metrics>";

    // Load string into a temporary XML DOM.

    var domNewRow = XDocument.CreateDOM();

    domNewRow.validateOnParse = false;

    domNewRow.async = false;

    domNewRow.loadXML(metricXml);

    domNewRow.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-06-03T00:09:57"');

     

    // Insert into the main DOM.

    metricList.appendChild(domNewRow.selectSingleNode("my:Fin_Phase_Metrics"));

    }

    catch(ex)

    {

    XDocument.UI.Alert("Could not insert Phase Metric row.\n\nError message:\n" + ex.Message);

    }

    }

    XDocument.UI.Alert("After the loop");

    }

     

     

    Based on the displays, I am going till the While loop and not inside it...

  • 04-15-2010 06:51 AM In reply to

    Re: Programatically copy Sharepoint list into Main data source - not copying data

    why dont you debug your template and find out what is going wrong, to debug

    save a copy of your submitted form on your machine,

    open the form template in design mode

    in the form -> preview -> preview settings -> form name give specify the saved form.

    open the code of the form and put debug points in the submit code and press f5. and try submitting the form.

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 04-15-2010 10:11 AM In reply to

    • vriyer
    • Not Ranked
    • Joined on 04-14-2010
    • Posts 6

    Re: Programatically copy Sharepoint list into Main data source - not copying data

    I did add displays on the code - as you can see.. Here is some more update.. In the initial definition of the list, I have the code as -

     var extlist = XDocument.GetDOM("Phase_Metrics").selectNodes("/myFields/dataFields/PhaseMetrics");

     in the path in the selectNodes, the xpath for the list has a dfs: prefix - /dfs:myFields/dfs:dataFields/dfs:PhaseMetrics. With this definition, it shows an error..

  • 06-30-2010 04:08 AM In reply to

    Re: Programatically copy Sharepoint list into Main data source - not copying data

    To copy SharePoint lists from one site to another site. It can be done in code as long as the two sites are on the same machine. It's fine if they are in different web applications, but it can't be from one server to another. If you need to copy from one server to another, you either need to do an export/import, or find a way to save the settings and import them on the new machine. You can use the SharePoint Web Services to accomplish this, though. Here's the code: // Instantiate web instances SPSite sourceSite = new SPSite(@http://sharepointserver:31001/); SPWeb sourceWeb = sourceSite.RootWeb; SPSite destSite = SPContext.Current.Site; SPWeb destWeb = destSite.RootWeb; // Get a reference to the source list SPList sourceList = sourceWeb.GetList("/Lists/Announcements"); // if the list exists on the destination site, delete it try { SPList temp = destWeb.Lists[sourceList.Title]; destWeb.Lists.Delete(temp.ID); } Read this blog for more information: http://subashandsharepoint.blogspot.com/2010/02/copy-sharepoint-list-programmatically.html Hope you find it useful.
    Filed under:
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.