MSDN > フォーラム ホーム > SharePoint - Business Data Catalog > Can I extract the BDC data in InfoPath form without writing specific BDC action
質問する質問する
 

回答の候補Can I extract the BDC data in InfoPath form without writing specific BDC action

  • 2009年1月22日 17:21Ananya ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    I have a InfoPath which write backs to my LOB system. Before writing the data back to the LOB system I have to retrive the data first from my LOB system. I already have a BDC which is retriving this data. Is it possible to retrive the BDC data into my InfoPath form without writing a BDC action. Can someone provide a solution for this or direct me to a forum or blog where I can find the solution

すべての返信

  • 2009年6月19日 17:12Ashish kanoongo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Ananya

    Did you fina any solution ? I am also looking for the same
  • 2009年6月19日 17:21Ram Gopinathan - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     回答の候補

    You could write a web service that uses the BDC object model to execute BDC entity methods and then add the webservice as datasource to infopath form
    here is sample code to call BDC entity methods via code

    #region using statements
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Portal;
    using Microsoft.Office.Server.ApplicationRegistry.MetadataModel;
    using Microsoft.Office.Server.ApplicationRegistry.Runtime;
    #endregion

    namespace Microsoft.SharePoint.Common
    {
        public class BDCWrapper
        {
            #region properties
            private string _lobInstanceName ;
            public string LobInstanceName
            {
                get
                {
                    return _lobInstanceName;
                }
            }
            private string _sspName;

            public string SSPName
            {
                get { return _sspName; }
            }
     
            private LobSystemInstance _lobInstance = null;
            public LobSystemInstance LobInstance
            {
                get
                {
                    if (_lobInstance == null)
                    {
                        //Microsoft.Office.Server.ApplicationRegistry.Infrastructure.SqlSessionProvider.Instance().SetSharedResourceProviderToUse(this.SSPName);
                        NamedLobSystemInstanceDictionary lobInstances = ApplicationRegistry.GetLobSystemInstances();
                        _lobInstance = lobInstances[this.LobInstanceName];
                    }
                    return _lobInstance;
                }
            }
            #endregion

            #region constructor
            public BDCWrapper(string lobInstanceName, string sspName)
            {
                this._lobInstanceName = lobInstanceName;
                this._sspName = sspName;
                //set shared resource provider to use if current Office Server Context is null
                if (Microsoft.Office.Server.ServerContext.Current == null)
                {
                    Microsoft.Office.Server.ApplicationRegistry.Infrastructure.SqlSessionProvider.Instance().SetSharedResourceProviderToUse(sspName);
                }
            }
            #endregion

            #region helper methods
            /// <summary>
            /// builds a data table schema based on the Entity Definition in LOB System
            /// </summary>
            /// <param name="fields">Field Collection</param>
            /// <returns>DataTable</returns>
            private DataTable BuildDataTableSchema(FieldCollection fields)
            {
                DataTable dt = new DataTable();
                foreach (Field f in fields)
                {
                    DataColumn column = new DataColumn(f.Name, Type.GetType(f.TypeDescriptor.TypeName));
                    dt.Columns.Add(column);
                }
                return dt;
            }
            #endregion

            #region public methods
            /// <summary>
            /// used to get data from LOB System using BDC
            /// </summary>
            /// <returns>DataTable</returns>
            public DataTable GetBDCData(string entityName, params object[] filterValues)
            {
                DataTable data = null;    
                Entity entity = this.LobInstance.GetEntities()[entityName];
                FilterCollection finderFilters = entity.GetFinderFilters();

                if (finderFilters.Count != filterValues.Length)
                {
                    throw new ApplicationException("Not enough filter values specified");
                }
                for (int i = 0; i < filterValues.Length; i++)
                {
                    switch (finderFilters[i].GetType().FullName)
                    {
                        case "Microsoft.Office.Server.ApplicationRegistry.Runtime.WildcardFilter":
                            WildcardFilter wf = (WildcardFilter)finderFilters[i];
                            wf.Value = filterValues[i];
                            break;
                        case "Microsoft.Office.Server.ApplicationRegistry.Runtime.ComparisonFilter":
                            ComparisonFilter cf = finderFilters[i] as ComparisonFilter;
                            cf.Value = filterValues[i];
                            break;
                        case "Microsoft.Office.Server.ApplicationRegistry.Runtime.LimitFilter":
                            LimitFilter lf = finderFilters[i] as LimitFilter;
                            lf.Value = Convert.ToUInt32(filterValues[i]);
                            break;
                    }
                }
               
                IEntityInstanceEnumerator entityInstanceEnumerator = entity.FindFiltered(finderFilters, this.LobInstance);
                data = BuildDataTableSchema(entity.GetFinderView().Fields);
               
                //populate rows into data table
                while (entityInstanceEnumerator.MoveNext())
                {
                    IEntityInstance entityInstance = entityInstanceEnumerator.Current;
                    DataRow row = data.NewRow();
                    foreach (Field f in entity.GetFinderView().Fields)
                    {
                        if (entityInstance[f] != null)
                        {
                            row[f.Name] = entityInstance[f];
                        }
                    }
                    data.Rows.Add(row);
                }
                return data;
            }
            public DataTable FindSpecific(object identifierValue, string entityName)
            {
                DataTable data = null;    
                Entity entity = this.LobInstance.GetEntities()[entityName];
                IEntityInstance entityInstance = entity.FindSpecific(identifierValue, this.LobInstance);
                data = BuildDataTableSchema(entity.GetSpecificFinderView().Fields);
                DataRow row = data.NewRow();
                foreach (Field f in entity.GetSpecificFinderView().Fields)
                {
                    if (entityInstance[f] != null)
                    {
                        row[f.Name] = entityInstance[f];
                    }
                }
                data.Rows.Add(row);

                return data;
            }
            #endregion
        }
    }

  • 2009年6月19日 17:47Ashish kanoongo ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Ramprakash

    Thanks for reply. Can you show me any live demo or send me complete code, so I can test it if it not agains your ethics?

    Ashi
  • 2009年6月19日 18:13Ram Gopinathan - MSFT ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Ashi,

    Sorry I don't have a live demo set to demonstrate the end to end scenario from infopath-webservice-bdc call via api
    the code pasted here is from a helper class I use in my projects for talking to BDC via API, you can just add it to your web service project and call methods in it
    It shouldn't be that hard to create a web service project add use the code I provided to execute BDC entity methods and wire up infopath form to consume web service
    if you have trouble let me know I will try to put something together over the weekend, no promises though
  • 2009年6月29日 12:15Manishrao Patil ユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダルユーザーのメダル
     
    Hi,

    I think you can do one thing, instead of showing bdc information in some BDC webparts you use DVWP of sharepoint designer which is clean, easy and still power enough.
    Since this webpart (DVWP) is purely xml and xslt driven so can easily play with it and redirect the user to the infopath form with required parameters (needless to say query string).
    I'm quiet confident that you will get good enough help online regarding xml and xslt in context to the DVWP.
    This approach is quiet easy and easy for maintanence.

    Manish Patil http://patilmanishrao.wordpress.com Posting is provided "AS IS" with no warranties, and confers no rights.