Professional Documents
Culture Documents
Conversion
Ahmed Hamidi
Lead Software Architect
Topics
s example will default todays date in Sale Order Entry, after Get New is called.
ost processing method directive on Sales Order GetNew.
ABL Code:
FOR FIRST ttOrderHed WHERE ttOrderHed.RowMod <>
NO-LOCK.
END.
C# Code:
foreach(var ttOrderHed_iterator in(from ttOrderHed_Row in
ttOrderHed
where ttOrderHed_Row.RowMod !=
select ttOrderHed_Row))
{
var ttOrderHedRow = ttOrderHed_iterator;
ttOrderHedRow.OrderDate = DateTime.Now;
}
2013 Epicor Software
Corporation
Exercise 1 Translation
ABL Code:
FOR FIRST ttOrderHed WHERE ttOrderHed.RowMod <>
NO-LOCK.
END.
C# Code:
foreach(var ttOrderHed_iterator in(from ttOrderHed_Row
in
ttOrderHed where ttOrderHed_Row.RowMod !=
select ttOrderHed_Row))
{
var ttOrderHedRow = ttOrderHed_iterator;
ttOrderHedRow.OrderDate = DateTime.Now;
}
Exercise 1 ERROR
Converted C# syntax:
foreach(var ttOrderHed_iterator in(from ttOrderHed_Row in
ttOrderHed where ttOrderHed_Row.RowMod !=
select ttOrderHed_Row))
Proper C# syntax:
foreach(var ttOrderHed_iterator in(from ttOrderHed_Row in
ttOrderHed where String.Equals( ttOrderHed_Row.RowMod, )
select ttOrderHed_Row))
is example will validate the State entered in the Customer Maintenance screen,
ich is free form, against a UD table.
eProcessing directive on Customer Update method
ABL Code:
FOR FIRST ttCustomer WHERE ttCustomer.RowMod = A NO-LOCK.
END.
END .
C# Code:
object THROW_PUBLIC = null;
Ice.Tables.UD40 UD40;
foreach(var ttCustomer_iterator in(from ttCustomer_Row in ttCustomer
where ttCustomer_Row.RowMod == A
select ttCustomer_Row))
{
var ttCustomerRow = ttCustomer_iterator;
if(((from UD40_Row in Db.UD40
where UD40_Row.Company == Session.CompanyID && UD40_Row.Key1 == ttCustomerRow.State &&
UD40_Row.Key2 == && UD40_Row.Key3 == && UD40_Row.Key4 == && UD40_Row.Key5 ==
select UD40_Row).Count() != 0) == false)
{
CallContext.Current.ExceptionManager.AddBLException("Invalid State");
THROW_PUBLIC = null;
}
}
2013 Epicor Software
Corporation
Exercise 2 Translation
ABL Code:
FOR FIRST ttCustomer WHERE ttCustomer.RowMod = A NO-LOCK.
END.
END .
C# Code:
object THROW_PUBLIC = null;
Ice.Tables.UD40 UD40;
foreach(var ttCustomer_iterator in(from ttCustomer_Row in ttCustomer
where ttCustomer_Row.RowMod == A
select ttCustomer_Row))
{
var ttCustomerRow = ttCustomer_iterator;
if(((from UD40_Row in Db.UD40 where UD40_Row.Company == Session.CompanyID
&& UD40_Row.Key1 == ttCustomerRow.State && UD40_Row.Key2 ==
&& UD40_Row.Key3 == && UD40_Row.Key4 == && UD40_Row.Key5 ==
select UD40_Row).Count() != 0) == false)
{
CallContext.Current.ExceptionManager.AddBLException("Invalid State");
THROW_PUBLIC = null;
}
}
his example will use a business object to create a new row in UD01 when an
BCCode entry is updated. Action File to BPM Custom Code.
PreProcessing directive on ABCCode Update method
ABL:
{Bpm/Bpm.i &OBJECT_NAME=AbcCode}
{bo/UD01/UD01_ds.i}
procedure UpdateBefore:
define input-output parameter table for ttAbcCode.
{&TRY_PRIVATE}
define variable hUD01 as handle.
find first ttAbccode no-lock no-error.
RUN bo\UD01\UD01.p PERSISTENT SET hUD01.
IF VALID-HANDLE (hUD01) THEN DO:
/*Create new record*/
RUN GETANEWUD01 IN hUD01 ( {&input-output_dataset_UD01DataSet} )
NO-ERROR.
find first ttUD01 where ttUD01.ROWMOD = 'A' no-lock no-error.
IF available ttUD01 THEN DO:
/*Populate fields*/
assign ttUD01.Company = CUR-COMP
ttUD01.Key1
= "AbcCode"
/*Table that was
affected*/
ttUD01.Key2
= "CountFreq"
/*Field that was
affected*/
ttUD01.Key3
= STRING(TIME,"HH:MM:SS") /*Time*/
ttUD01.Key4
= STRING(RECID(ttUD01)) /*To make the
records unique*/
ttUD01.Date01
= TODAY
/*Date*/
ttUD01.Number01 = ttAbcCode.CountFreq
/*New Value*/
ttUD01.ShortChar01 = DCD-USERID.
/*User id*/
/*Commit record*/
RUN UPDATE IN hUD01 ( {&input-output_dataset_UD01DataSet} ) NOERROR.
END. /*IF available ttUD01*/
/*Clean up*/
delete object hUD01.
END. /*IF VALID-HANDLE (hUD01)*/
{&CATCH_PRIVATE}
end procedure.
2013 Epicor Software
Corporation
C#:
/* TO DO: replace DataSet variables with typed datasets. Add contract
reference if necessary. */
var UD01DataSet = new System.Data.DataSet();
var ttAbccode_xRow = (from ttAbccode_Row in ttAbccode
select ttAbccode_Row).FirstOrDefault();
hUD01 =
Ice.Assemblies.ServiceRenderer.GetService<Ice.Contracts.UD01SvcContr
act>(Db);
if (hUD01 != null)
{
hUD01.GETANEWUD01(UD01DataSet);
var ttUD01_xRow = (from ttUD01_Row in ttUD01
where string.Equals(ttUD01_Row.RowMod,
IceRow.ROWSTATE_ADDED, StringComparison.OrdinalIgnoreCase)
select ttUD01_Row).FirstOrDefault();
if (ttUD01_xRow != null)
{
ttUD01_xRow.Company = Session.CompanyID;
ttUD01_xRow.Key1 = "AbcCode";
/*Table that was
affected*/
ttUD01_xRow.Key2 = "CountFreq";
/*Field that was affected*/
ttUD01_xRow.Key3 = System.Convert.TimeToString(DateTime.Now,
"HH:MM:SS"); /*Time*/
ttUD01_xRow.Key4 = ttUD01_xRow.SysRowID; /*To make the
records unique*/
ttUD01_xRow["Date01"] = DateTime.Now;
/*Date*/
ttUD01_xRow["Number01"] = ttAbccode_xRow.CountFreq;
/*New
Value*/
ttUD01_xRow["ShortChar01"] = Session.UserID;
/*User id*/
/*Commit record*/
hUD01.UPDATE(UD01DataSet);
}/*IF available ttUD01*/
/*Clean up*/
hUD01.Dispose();
}
Converted C#:
/* TO DO: replace DataSet variables with typed datasets. Add contract
reference if necessary. */
Common Errors
Case Sensitivity
Use Of Unassigned Local Variable Message
E10 Equivalent to Row Mod = U or A
Case Sensitivity
For those who do not work with C# often, remember that it is case sensitive. For example,
look at the below simple query:
var CustomerRecs = (from r in Db.customer
from r_UD in Db.Customer_UD
where r.SysRowID == r_UD.ForeignSysRowID &&
r.Company == Session.CompanyID &&
r.CustNum == ttOrderHedRow.CustNum
select r_UD).FirstOrDefault();
This query will produce the following error message when you attempt to compile the BPM:
Description: There is at least one compilation error.
Details:
Error CS1061: 'Erp.ErpContext' does not contain a definition for 'customer' and no
extension method 'customer' accepting a first argument of type 'Erp.ErpContext' could be
found (are you missing a using directive or an assembly reference?)
Notice that the error message has customer with a lower case C? Change the following line
Change the first line to an upper case C as below and the BPM compiles without error.
var CustomerRecs = (from r in Db.Customer
of
FOR EACH
FOR FIRST
RUN PERSISTENTLY
Raise an exception
Use PublishInfoMessage
Send an email
// EMAIL BEGIN
var splitter = new[] { ';' };
var mailer = new Epicor.Customization.Bpm.Implementation.AsyncSmtpMailer();
var message = new System.Net.Mail.MailMessage();
var from = BPM_from; 17 Revision 3
message.From = new System.Net.Mail.MailAddress(from);
var to = BPM_to;
foreach (var address in to.Split(splitter, StringSplitOptions.RemoveEmptyEntries))
{
message.To.Add(new System.Net.Mail.MailAddress(address));
}
var cc = BPM_cc;
foreach (var address in cc.Split(splitter, StringSplitOptions.RemoveEmptyEntries))
{
message.CC.Add(new System.Net.Mail.MailAddress(address));
}
var subject = BPM_subject;
message.Subject = subject;
var body = BPM_body;
message.Body = body;
mailer.Send(this.Db, message, this.CompanyID);
//
Programming Guide
Accessible on code converter about page
Helpful hints and how-to info
Questions