Cообщество разработчиков на платформе Microsoft > Форумы > 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

Все ответы

  • 19 июня 2009 г. 17:12Ashish kanoongo Медали пользователяМедали пользователяМедали пользователяМедали пользователяМедали пользователя
     
    Ananya

    Did you fina any solution ? I am also looking for the same
  • 19 июня 2009 г. 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
        }
    }

  • 19 июня 2009 г. 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
  • 19 июня 2009 г. 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
  • 29 июня 2009 г. 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.