writing values in different lists!?!?!?! - InfoPath Dev
in

InfoPath Dev

writing values in different lists!?!?!?!

Last post 10-27-2006 12:06 AM by Patrick Halstead. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 10-17-2005 12:02 AM

    writing values in different lists!?!?!?!

    hello,

    i can save my form without problems (that`s fine ;-)) ... now i think about how to write different fields (values) to other lists.

    e.g. i have a form that is used for the case x and this form has some fields to enter names of persons. now i need this names also in an other list of sharepoint. at this time i have to fill this list by hand with the same persons i have entered in the form. how can i solve this problem?

    is there a web service from sharepoint that can do this job?
    now i use c# in my code behind. is there a way to do this by code?
    should i use a assambly in my form-library?

    please help
  • 10-18-2005 12:30 AM In reply to

    Re: writing values in different lists!?!?!?!

    Hi Mephisto,
    You can use the SharePoint Contacts. Check out Greg's latest HowTo article on how to set up [me] filters for forms saved from InfoPath.

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 10-18-2005 01:17 AM In reply to

    Re: writing values in different lists!?!?!?!

    hello patrick,

    thx for your help, but this is not the thing i need!

    i will try to explain it with other words. i have an infopath form with different fields. if i save this form to sharepoint the xml-file is displayed in a sharepoint-form-library. now i need values from some fields also in a custom list of my sharepoint. the custom list is a normal list so i have to add the values all new item. i want to do this by code, but i`m not able to enter a list because i can`t find a way to do.

    any help?
  • 10-19-2005 11:31 PM In reply to

    Re: writing values in different lists!?!?!?!

    Hi Mephisto,
    Still confused. So you want to reuse some of the saved values in your custom list? Or do you want to create items in your custom list from the saved form? Does your custom list display the values in a dropdown? SharePoint has many Web services and an extensive programming model. If you need to change some values on save, you can do this from code in InfoPath. If however, your custom list needs to access promoted column values from the Form Library, I think you may be out of luck. You might look at calculated columns but that's mainly for static display.


    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 10-20-2005 05:29 AM In reply to

    Re: writing values in different lists!?!?!?!

    You can add fields from InfoPath to custom lists in SPS using managed code.

    One way is to usehttp://<yourserver>/<yoursite>/_vti_bin/lists.asmx?op=UpdateListItems

    What you will to do is simply create a batch XmlNode with the relevant items and either insert or update items in an existing list.

    code sample:
    string strBatch = "<Method ID='" + number + "' Cmd='New'>" +
    "<Field Name='ID'>New</Field>" +
    "<Field Name='Title'>" + equipmentText + "</Field>" +
    "<Field Name='Equipment_x0020_Type'>" + typeText + "</Field>" +
    "<Field Name='Recommendation'>" + recommendationText + "</Field>" +
    "<Field Name='Area'>" + areaID + "</Field>" +
    "</Method>";
    XmlDocument xmlDoc = new System.Xml.XmlDocument();
    System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
    elBatch.SetAttribute("OnError","Continue");
    elBatch.InnerXml = strBatch;

    //call webservice to create item
    //replace areaEquipmentGuid with your own list GUID
    XmlNode ndReturn = listService.UpdateListItems( areaEquipmentGuid.ToString(), elBatch );

    the above code assumes an instantiated object "listService" of the above webservice (add web reference in VS.NET)

    known problems:
    the above will work for custom list items (announcements, tasks etc) but if you want to upload images, lists.asmx cant help you.
    Here you will have to experiment with either Remote Procedure Calls (check FPRCP in SPPT SDK), create a Custom Web Service (recommended), webDAV or simply create a .NET WebRequest / HttpWebRequest.

    also images are encoded with a special header, but fortunately Patrick's book on InfoPath has the solution on how to remove that ;-)

    let me know if you need the code, since i took the liberty of translating Matthew Blain's code to C#

    custom web services in SPPT
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/odc_writingcustomwebservicesforsppt.asp

    HTH
    //AndersR


  • 10-20-2005 06:08 AM In reply to

    Re: writing values in different lists!?!?!?!

    hello AndersR,

    thx for the example but i don`t understand how to do it. is there a larger documentation for that topic in the www?

    i found this code but i cant use this because i can`t use the "context" in the first line out of my infopath-form. i believe it only functions within sharepoint????

    SPWeb mySite = SPControl.GetContextWeb(Context);
    SPListItemCollection listItems = mySite.Lists[TextBox1.Text].Items;
    SPListItem item = listItems.Add();
    item["Title"] = TextBox2.Text;
    item["Stock"] = Convert.ToInt32(TextBox3.Text);
    item["Return Date"] = Convert.ToDateTime(TextBox4.Text);
    item["Employee"] = TextBox5.Text;
    item.Update();
    }

    the first line references a site in sharepoint. in the second it specifies the list. is there a way to set the right site (url??) by hand? e.g. SPWeb mySite = "http://sharepoint/managers/" so i don`t need the "context"????

    this should be possible but how?
  • 10-20-2005 06:26 AM In reply to

    Re: writing values in different lists!?!?!?!

    Hi

    the above will never work (unless you install a portal on every users machine ;-)

    remember, you can look at your InfoPath form as a smartclient that the user executes locally. You can not use server logic on a local client.

    you need to use the sharepoint web services lists.asmx etc

    ok ill try and guide you.

    First, ill presume you are familiar with using managed code in InfoPath.

    add a web reference to your web service in VS.NET.http://<yourserver>/<yoursite>/_vti_bin/lists.asmx

    Ill assume its called SPSAddListItems

    Instantiate your object:

    private SPSAddListItems.Lists listService = new SPSAddListItems.Lists();

    You will need to give credentials to this web service. I usually use DefaultCredentials.
    Put these in _Startup event

    listService.Credentials = System.Net.CredentialCache.DefaultCredentials;

    Now find the field/fields you will save in a custom list:

    IXMLDOMNode myFields = e.XDocument.DOM.selectSingleNode("/my:myFields/my:mySharepointFields");

    The rest of the code is as specified above. The XML is actually CAML that you feed the web service, and can create/update delete several items at the time:

    For more detail check out the reference in the sdk:

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/spptsdk/html/soapmListsUpdateListItems_SV01034352.asp

    HTH
    //AndersR



  • 10-20-2005 06:55 AM In reply to

    Re: writing values in different lists!?!?!?!

    hello again,

    i tryed the code like this:

    string strBatch = "<Method ID='1' Cmd='New'>" +
    "<Field Name='Besucher'>Testbenutzer</Field>" +
    "</Method>";
    XmlDocument xmlDoc = new System.Xml.XmlDocument();
    System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
    elBatch.SetAttribute("OnError","Continue");
    elBatch.InnerXml = strBatch;

    XmlNode ndReturn = listService.UpdateListItems("Besucherliste", elBatch );

    "Besucher" is a column in my custom list. "Besucherliste" is the name of my list. the reference is included also the credentials.....

    now i get this error:

    System.Web.Services.Protocols.SoapException
    Eine Ausnahme vom Typ Microsoft.SharePoint.SoapServer.SoapServerException wurde ausgelöst.
    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
    at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
    at TestProjekt_InfoPath.SPSAddListItems.Lists.UpdateListItems(String listName, XmlNode updates) in C:\meineProjekte\TestProjekt-InfoPath\Web References\SPSAddListItems\Reference.cs:line 239
    at TestProjekt_InfoPath.TestProjekt_InfoPath.klick_OnClick(DocActionEvent e) in c:\meineprojekte\testprojekt-infopath\formcode.cs:line 51
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent

    do you have an idea what i did wrong?
  • 10-20-2005 12:03 PM In reply to

    Re: writing values in different lists!?!?!?!

    Hi

    could you paste your full source please?

    my german is rather lacking im afraid ;-)

    //AndersR


  • 10-20-2005 11:39 PM In reply to

    Re: writing values in different lists!?!?!?!

    o.k. here`s the full source-code:


    using System;
    using System.Xml;
    using Microsoft.Office.Interop.InfoPath.SemiTrust;

    [assembly: System.ComponentModel.DescriptionAttribute("InfoPathStartupClass, Version=1.0, Class=TestProjekt_InfoPath.TestProjekt_InfoPath")]

    namespace TestProjekt_InfoPath
    {
    [InfoPathNamespace("xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-20T11-50-07\" xmlns:xsf=\"http://schemas.microsoft.com/office/infopath/2003/solutionDefinition\" xmlns:msxsl=\"urn:schemas-microsoft-com:xslt\" xmlns:xdUtil=\"http://schemas.microsoft.com/office/infopath/2003/xslt/Util\" xmlns:xdXDocument=\"http://schemas.microsoft.com/office/infopath/2003/xslt/xDocument\" xmlns:xdMath=\"http://schemas.microsoft.com/office/infopath/2003/xslt/Math\" xmlns:xdDate=\"http://schemas.microsoft.com/office/infopath/2003/xslt/Date\" xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\" xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" xmlns:s0=\"http://schemas.microsoft.com/sharepoint/soap/directory/\" xmlns:ns1=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-03-16T06-17-54\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"")]
    public class TestProjekt_InfoPath
    {
    private XDocument thisXDocument;
    private Application thisApplication;

    private SPSAddListItems.Lists listService = new SPSAddListItems.Lists();

    public void _Startup(Application app, XDocument doc)
    {
    thisXDocument = doc;
    thisApplication = app;

    listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
    }

    public void _Shutdown()
    {
    }

    [InfoPathEventHandler(EventType=InfoPathEventType.OnLoad)]
    public void OnLoad(DocReturnEvent e)
    {
    thisXDocument.DataObjects["DummyUsers"].DOM.loadXML(thisXDocument.DataObjects["Users"].DOM.xml);
    }

    [InfoPathEventHandler(MatchPath="klick", EventType=InfoPathEventType.OnClick)]
    public void klick_OnClick(DocActionEvent e)
    {
    string strBatch = "<Method ID='1' Cmd='New'>" +
    "<Field Name='Besucher'>Testbenutzer</Field>" +
    "</Method>";
    XmlDocument xmlDoc = new System.Xml.XmlDocument();
    System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
    elBatch.SetAttribute("OnError","Continue");
    elBatch.InnerXml = strBatch;

    XmlNode ndReturn = listService.UpdateListItems("Besucherliste", elBatch );
    }

    }
    }

    i hope this helps *g*
  • 10-21-2005 02:54 AM In reply to

    Re: writing values in different lists!?!?!?!

    Hi

    when adding a new field, you must supply <Field Name='ID>New</Field> along with the fields you need to change, so add that as the first <Field > element before <Field Name='Besucher'>Testbenutzer</Field>

    Also you might want to check the return XML for errors.

    I have a small util you can have:

    Add this line after the web service call:

    if ( !UpdateSuccessful(ndReturn) )
    throw new Exception("Survey Description creation failed");//you will need to implement your own try/catch somewhere in the code

    //here is the method to check return xml
    private bool UpdateSuccessful( XmlNode returnXml )
    {

    XmlDocument document = new XmlDocument();
    document.LoadXml(returnXml.OuterXml);

    // associate with the xmlns namespaces
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable);
    nsmgr.AddNamespace(SharePointNamespacePrefix,SharePointNamespaceURI);
    nsmgr.AddNamespace(ListItemsNamespacePrefix,ListItemsNamespaceURI);
    nsmgr.AddNamespace(PictureLibrariesNamespacePrefix,PictureLibrariesNamespaceURI);
    nsmgr.AddNamespace(WebPartsNamespacePrefix,WebPartsNamespaceURI);
    nsmgr.AddNamespace(DirectoryNamespacePrefix,DirectoryNamespaceURI);

    XmlNodeList errorCodes = document.SelectNodes("//sp:ErrorCode",nsmgr);

    for ( int x=0; x<errorCodes.Count; x++ )
    {
    if(errorCodes[x].SelectSingleNode(".") == null
    || errorCodes[x].SelectSingleNode(".").InnerText != "0x00000000" )
    return false;
    System.Diagnostics.Debug.WriteLine("Area returnXML ErrorCode[" +errorCodes[x].SelectSingleNode(".").InnerText+ "]");
    }

    return true;
    }


    //and here is the namespace prefix and uri's used in sharepoint (prob. not complete)
    //add those as global fields

    // all the possible namespaces used by SharePoint
    const string SharePointNamespacePrefix = "sp";
    const string SharePointNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/";
    const string ListItemsNamespacePrefix = "z";
    const string ListItemsNamespaceURI = "#RowsetSchema";
    const string PictureLibrariesNamespacePrefix = "y";
    const string PictureLibrariesNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/ois/";
    const string WebPartsNamespacePrefix = "w";
    const string WebPartsNamespaceURI = "http://schemas.microsoft.com/WebPart/v2";
    const string DirectoryNamespacePrefix = "d";
    const string DirectoryNamespaceURI = "http://schemas.microsoft.com/sharepoint/soap/directory/";
    const string RowSetNamespaceURI = "urn:schemas-microsoft-com:rowset";
    const string RowSetNamespacePrefix = "rs";

    HTH
    //AndersR




  • 10-25-2005 06:07 AM In reply to

    Re: writing values in different lists!?!?!?!

    hi,

    thx for your invested time. now i solved my problem using form-library-event-handler. if a new xml-file was created the code reads the columns in the list and write it to my custom list.
    i tested with your code but it won`t function in my case. i don´t know why!

    thx
    nasgul
  • 10-26-2006 10:15 AM In reply to

    • Afzal
    • Not Ranked
    • Joined on 10-26-2006
    • USA
    • Posts 14

    Re: writing values in different lists!?!?!?!


    Hi Nasgul,

    I have the same problem as mentioned in your post. Could please help me in understanding how did you solve the problem using form library evewnt handler.

    I really appreciate your help in this.

    Thanks in advance.

    quote:
    Originally posted by mephisto

    hi,

    thx for your invested time. now i solved my problem using form-library-event-handler. if a new xml-file was created the code reads the columns in the list and write it to my custom list.
    i tested with your code but it won`t function in my case. i don´t know why!

    thx
    nasgul

  • 10-27-2006 12:06 AM In reply to

    Re: writing values in different lists!?!?!?!

    Hi Afzal,
    Have you installed the SharePoint SDK? It should have samples of how to create an event handler. Good luck!
    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (14 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.