Search code examples
c#epicorerp

How can I access UD fields in Epicor10 business objects outside of Epicor?


In Epicor 9 it was fairly easy to open Visual Studio and create a project and use the Epicor libraries to access its Business Objects (BOs). So, for instance the Part could be accessed by including the library Epicor.Mfg.Part and newing up a Part object. Then it was easy to get information for a part by calling Part.GetByID("partnum");. This would return a PartDataSet.

It is different but not so difficult to do the same thing in Epicor 10. However, I have noticed that the PartDataSet does not contain any UD fields, even UD fields that have been properly set up in Epicor10.

How can the UD fields be accessed when tapping into Epicor 10 through its business objects?

EDIT:

using Erp.BO;
using Erp.Proxy.BO;

// ...

var binding = Epicor.ServiceModel.StandardBindings.NetTcp.UsernameWindowsChannel();

var cc = new ClientCredentials();
var cred = cc.UserName;
cred.UserName = "****";
cred.Password = "****";
DnsEndpointIdentity ep = new DnsEndpointIdentity("****");

var quoteBo = new QuoteImpl(binding, new Uri("net.tcp://****/Erp/BO/Quote.svc"), cc, ep);

var qds = new QuoteDataSet();
var hed = qds.QuoteHed.NewQuoteHedRow(); // type: QuoteDataSet.QuoteHedRow

// I am not getting UserDefinedColumns as a member of hed.
// This gives me a compiler error.
qds.QuoteHed[0].UserDefinedColumns["Custom_c"] = "value";

Solution

  • It is still fairly easy, the DS returned by the call to the BO will be defined in the contract DLL found on both the client and the server, as this file needs to be distributed to the client machines the UD fields are not added to it. It would cause too many client updates.

    This means the Visual Studio cannot look at the contract assembly to determine the field names. Instead, you access the field using the columnName indexer i.e:

    class Program
    {
        static void Main(string[] args)
        {
            // Hard-coded LogOn method 
            // Reference: Ice.Core.Session.dll
            Ice.Core.Session session = new Ice.Core.Session("manager", "manager", "net.tcp://AppServer/MyCustomerAppserver-99999-10.0.700.2");
    
            // References: Epicor.ServiceModel.dll, Erp.Contracts.BO.ABCCode.dll
            var abcCodeBO = Ice.Lib.Framework.WCFServiceSupport.CreateImpl<Erp.Proxy.BO.ABCCodeImpl>(session, Erp.Proxy.BO.ABCCodeImpl.UriPath);
    
            // Call the BO methods
            var ds = abcCodeBO.GetByID("A");
            var row = ds.ABCCode[0];
    
            System.Console.WriteLine("CountFreq is {0}", row.CountFreq);
            System.Console.WriteLine("CustomField_c is {0}", row["CustomField_c"]);
            System.Console.ReadKey();
        }
    }
    

    UserDefinedColumns is defined in Epicor.ServiceModel but is inaccessible as it is an internal property of Ice.IceRow which Erp.Tablesets.QuoteHedRow inherits from.