none
Managed Metadata Columns & Infopath

    Question

  • Hey All, 

    Please guide me with a problem I have. I created an Infopath form and published it on a Form Library. It is coming properly.  Now, the next thing I wanna do is I want to add a taxonomy/managed metadata column into it. So, please tell me the way to do it programatically using code-behind.

     

    Please, help me.

    Rajdeep

    Friday, April 29, 2011 10:43 AM

All replies

  • In code behind you have to remember that a web browser can only understand HTML and JavaScript.  With this said this post below will show you how to place JavaScript like functions behind buttons on a InfoPath Form. 

    http://johanolivier.blogspot.com/2010/08/infopath-2010-development-part-1-add.html

    If you are looking for more power then this and access the SharePoint object model.  You might want to look at this link to the client side object model which you can also use as you would from JavaScript.

    http://www.zimmergren.net/archive/2009/11/30/sp-2010-getting-started-with-the-client-object-model-in-sharepoint-2010.aspx

    Good Luck,

    Gary


    Gary Newman MCSE, MCT, CCNA MCDBA, MCAD, MCSA MCTS SharePoint 2007 Dev & Admin MCPD SharePoint 2010 Development
    Friday, April 29, 2011 1:42 PM
  • Gary,

    Thanks for your help but the links you've given  contains very basic information that I already know.

    Actually I wanna use Managed Metadata into combo box present in my Infopath form.

    Friday, April 29, 2011 2:20 PM
  • Hi Rajdeep,

    You could use the Taxonomy web services to get the managed metadata, and then present it in the combobox in InfoPath.

    1. Open InfoPath
    2. Click "Data" > "From Web Service" > "From SOAP web service"
    3. Type the URL: http://<server>/_vti_bin/TaxonomyClientService.asmx
    4. Click "Next"
    5. Select GetTermSets
    6. Assign the parameters' value
    7. Click Next
    8. Click Next
    9. Click Finish(You can check "Automatically retrieve data when form is opened")

    Now, you will get a datasource with field "GetTermSetResult".
    The next step we need to do is using custom code in InfoPath to convert the GetTermSetResult to datafields in InfoPath.

    For more information, please see:
    Unable to GetTermSets from TaxonomyClientService(Resolved): http://social.technet.microsoft.com/Forums/en-us/sharepoint2010programming/thread/2a1a12f2-6008-475f-9d2b-fd4f328432ff
    Populating a repeating table in InfoPath programmatically: http://www.stevenboldt.com/blog/post/2010/03/02/Populating-a-repeating-table-in-InfoPath-programmatically.aspx

    If you have any more questions, please feel free to ask.

    Thanks,
    Jinchun Chen


    Jin Chen - MSFT
    • Proposed as answer by Sjoukje Zaal Tuesday, February 07, 2012 7:29 AM
    Wednesday, May 04, 2011 9:55 AM
    Moderator
  • Hi Jinchun,

    How do I get the values to be used for the parameters for 'GetTermSets'?

    Thanks for your help!

     

    Monday, February 06, 2012 11:19 PM
  • Have a look at this blog post:

    http://richardihogan.wordpress.com/2011/11/09/sharepoint-2010-powershell-script-to-retreive-meanaged-meta-data-service-and-terms-store-ids/


    Kind regards, Frank-Ove

    Thursday, March 01, 2012 11:38 AM
  • I'm trying to read the data coming back from the Datasource, but all attempts just fail.

    When I get to the foreach, only 1 item is there. Anyone see what I'm doing wrong? I'm not sure if the XPathNodeIterator is correctly set...

            private void GetTerms()
            {
                //select the secondary data source
                XPathNavigator root = this.DataSources["GetTermSets"].CreateNavigator();
                XPathNodeIterator xDomNodes = root.Select("/dfs:myFields/dfs:dataFields/tns:GetTermSetsResponse/tns:GetTermSetsResult", this.NamespaceManager);
    
                foreach (XPathNavigator xDom in xDomNodes)
                {
                    XmlDocument doc = new XmlDocument();
    
                    //set first field(column)
                    XmlNode group = doc.CreateElement("RepeatingTable", NamespaceManager.LookupNamespace("my"));
                    XmlNode field = doc.CreateElement("RPField1", NamespaceManager.LookupNamespace("my"));
                    XmlNode node = group.AppendChild(field);
                    XPathNavigator nav = xDom.SelectSingleNode("@a32", NamespaceManager);
                    node.InnerText = nav != null ? nav.Value : string.Empty;
    
                    //set second field(column)
                    field = doc.CreateElement("RPField2", NamespaceManager.LookupNamespace("my"));
                    node = group.AppendChild(field);
                    //node.InnerText = xDom.SelectSingleNode("@Field2", NamespaceManager).Value;
    
                    doc.AppendChild(group);
    
                    //populate repeating table with xml of database values
                    //MainDataSource.CreateNavigator().SelectSingleNode("/my:MineFelt/my:group1", this.NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
                }
    
                //remove empty row
                XPathNavigator firstNode = MainDataSource.CreateNavigator().SelectSingleNode("/my:MineFelt/my:group1/my:group2[1]", NamespaceManager);
                firstNode.DeleteSelf();
            }


    Here's the XML that's returned from the datasource:

    <Container>
      <TermStore>
        <TS a9="4feca2c8-eeed-478e-8016-cea59846fa8f" a17="true" a11="" a16="false" a12="Målgruppe" a68="" />
        <T a9="79c0cb4f-0c23-48e4-b6e2-c4b0700c1107" a21="false" a61="0">
          <LS>
            <TL a32="Hele Sira-Kvina" a31="true" />
          </LS>
          <DS />
          <TMS>
            <TM a24="4feca2c8-eeed-478e-8016-cea59846fa8f" a12="Målgruppe" a40="" a17="true" a67="" a45="79c0cb4f-0c23-48e4-b6e2-c4b0700c1107" a69="true" />
          </TMS>
        </T>
        <T a9="1a99dab4-d842-489a-bef3-423a657eed11" a21="false" a61="0">
          <LS>
            <TL a32="Kraftverksgruppe felles" a31="true" />
          </LS>
          <DS />
          <TMS>
            <TM a24="4feca2c8-eeed-478e-8016-cea59846fa8f" a12="Målgruppe" a40="" a17="true" a67="" a45="1a99dab4-d842-489a-bef3-423a657eed11" a69="true" />
          </TMS>
        </T>
        <T a9="e22733a8-6a5c-48eb-adca-a41f0af2f3e5" a21="false" a61="0">
          <LS>
            <TL a32="Kraftverksgruppe nord" a31="true" />
          </LS>
          <DS />
          <TMS>
            <TM a24="4feca2c8-eeed-478e-8016-cea59846fa8f" a12="Målgruppe" a40="" a17="true" a67="" a45="e22733a8-6a5c-48eb-adca-a41f0af2f3e5" a69="true" />
          </TMS>
        </T>
        <T a9="372c4647-6867-4b9d-83b3-3d3519245cee" a21="false" a61="0">
          <LS>
            <TL a32="Kraftverksgruppe sør" a31="true" />
          </LS>
          <DS />
          <TMS>
            <TM a24="4feca2c8-eeed-478e-8016-cea59846fa8f" a12="Målgruppe" a40="" a17="true" a67="" a45="372c4647-6867-4b9d-83b3-3d3519245cee" a69="true" />
          </TMS>
        </T>
      </TermStore>
    </Container>

    Hope someone can help me.


    Kind regards, Frank-Ove


    • Edited by Frank-Ove Wednesday, March 07, 2012 10:50 PM Shortened XML example
    Wednesday, March 07, 2012 10:46 PM
  • Yes you only get 1 response but the contents is XML itself. Therefore, you need to load that in as an XML document and then loop through the terms.

                    string resultXML = rows.Current.SelectSingleNode("tns:GetTermSetsResult", NamespaceManager).Value.ToString();
                    XmlDocument termSetXML = new XmlDocument();
                    termSetXML.LoadXml(resultXML);
                    XmlNodeList terms = termSetXML.GetElementsByTagName("T");
                    foreach (XmlNode term in terms)
                    {

                            **** do what you need to do here

                    }

    A full solution will be described in SharePoint 2010 Managed Metadata Unleashed: http://www.amazon.com/gp/product/0672336308/ref=as_li_ss_tl?ie=UTF8&camp=1789&creative=390957&creativeASIN=0672336308&linkCode=as2&tag=stevemaspath-20


    • Edited by SteveTheManMann Monday, August 20, 2012 1:23 PM corrected title
    Monday, August 20, 2012 1:23 PM