Call Business Object Using C# Code in Epicor 10

Home  /  Transforming Business Through Software  /  Business Leaders Maximizing Technology  /  Call Business Object Using C# Code in Epicor 10

Call Business Object Using C# Code

Call Business Object Using C# Code

A couple weeks ago we posted how to do this using ABL?4GL code; however we received several inquires regarding the code for performing this same action in Epicor version 10.

Below is the source code that you can insert to automate Epicor business processes by calling a business object using C# code.

Here is the source.

 
Method directive on ABCCode.Update 
 
add reference to UD01 assembly: 
Ice.Contracts.BO.UD01 
 
no "using" statements required 
 
 
/*Delcare a UD01DataSet variable */ 
var UD01DataSet = new  Ice.Tablesets.UD01Tableset(); 
 
/* Declare variable hUD01 of type Ice.Contracts.UD01SvcContract and set its value to null */ 
Ice.Contracts.UD01SvcContract hUD01 = null; 
 
/* Select the first ttABCCode if it exists and store it in a new variable ttAbccode_xRow */ 
var ttAbccode_xRow = (from ttAbccode_Row in ttABCCode 
                      select ttAbccode_Row).FirstOrDefault(); 
 
/*Set the value of hUD01 */ 
hUD01 = Ice.Assemblies.ServiceRenderer.GetService(Db); 
 
/* If hUD01 is not null: */ 
if (hUD01 != null) 
{ 
/* call the hUD01 object's GetaNewUD01 method and put the result into the UD01DataSet variable */ 
    hUD01.GetaNewUD01(ref UD01DataSet); 
 
    /* Get the first row from the UD01DataSet, if it exists */ 
    var ttUD01_xRow = (from ttUD01_Row in UD01DataSet.UD01 
                       where ttUD01_Row.RowMod == "A" 
                       select ttUD01_Row).FirstOrDefault(); 
 
    if (ttUD01_xRow != null) 
    { 
        /* Assign values in the new UD01 record. */ 
        ttUD01_xRow.Company = Session.CompanyID; 
        ttUD01_xRow.Key1 = "AbcCode";               /*Table that was affected*/ 
        ttUD01_xRow.Key2 = "CountFreq";             /*Field that was affected*/ 
        ttUD01_xRow.Key3 = DateTime.Now.ToString("HH:MM:SS"); /*Time*/ 
        ttUD01_xRow.Key4 = System.Guid.NewGuid().ToString();   /*Unique Identifier*/ 
        ttUD01_xRow.Date01 = DateTime.Now;                   /*Date*/ 
        ttUD01_xRow.Number01 = ttAbccode_xRow.CountFreq;     /* Value from AbcCode */ 
        ttUD01_xRow.ShortChar01 = Session.UserID;            /*User id*/ 
        /*Commit record*/ 
        hUD01.Update(ref UD01DataSet); 
    } 
}

Can the experts at Datix help you with a problem?


While You’re Here reading about how to call a business object using C# code:

3 Comments so far:

  1. I find it good practice not to ignore errors as they would cause this code to fail silently and do nothing. Instead of checking for “if (hUD01 != null)…” I’d look for if (hUD01 == null)” and throw an error if it is. I.e.

    Ice.Contracts.UD01SvcContract ud01BusinessObject = Ice.Assemblies.ServiceRenderer.GetService(Db);
    if (ud01BusinessObject== null)
    throw new ApplicationException(“Could not render service Erp.Contracts.UD01SvcContract”);

    This also removes a level of { }, which would otherwise contribute to “arrow code”.

  2. Martin says:

    I was able to make it work (on Erp.Quote.Update method directive, post-processing) however, when trying to update some of its child tables (QuoteDtl.LineDesc) in that same BPM, nothing gets written in DB (no error of any kind though). Can you assist?

    Here is my code:

    var quoteTable = new Erp.Tablesets.QuoteTableset();
    Erp.Contracts.QuoteSvcContract hQ = null;

    hQ = Ice.Assemblies.ServiceRenderer.GetService(Db);

    if (hQ != null)
    {

    quoteTable = hQ.GetByID(1000);

    var tt_xRow = (from tt_Row in quoteTable.QuoteDtl where tt_Row.QuoteLine==1
    select tt_Row).FirstOrDefault();

    if (tt_xRow != null)
    {

    tt_xRow.LineDesc=”test”;
    hQ.Update(ref quoteTable);

    }
    }

  3. Hi, would you have an example how to use (run) a business object outside Epicor 10 (so NOT from within a bpm of data-directive) ?
    I want to run a c# program that runs a business object (for example salesorder) . In that program I can invoke the methods (so I can create a salesordes using the Epicor 10 logic).

Leave a Reply

Your email address will not be published. Required fields are marked *