You are on page 1of 38

Converted Code Programming Guide

Epicor ERP 10.0.700


Disclaimer
This document is for informational purposes only and is subject to change without notice. This document and its
contents, including the viewpoints, dates and functional content expressed herein are believed to be accurate as of its
date of publication. However, Epicor Software Corporation makes no guarantee, representations or warranties with
regard to the enclosed information and specifically disclaims any applicable implied warranties, such as fitness for a
particular purpose, merchantability, satisfactory quality or reasonable skill and care. As each user of Epicor software is
likely to be unique in their requirements in the use of such software and their business processes, users of this document
are always advised to discuss the content of this document with their Epicor account manager. All information contained
herein is subject to change without notice and changes to this document since printing and other important information
about the software product are made or published in release notes, and you are urged to obtain the current release
notes for the software product. We welcome user comments and reserve the right to revise this publication and/or
make improvements or changes to the products or programs described in this publication at any time, without notice.
The usage of any Epicor software shall be pursuant to an Epicor end user license agreement and the performance of
any consulting services by Epicor personnel shall be pursuant to Epicor's standard services terms and conditions. Usage
of the solution(s) described in this document with other Epicor software or third party products may require the purchase
of licenses for such other products. Where any software is expressed to be compliant with local laws or requirements
in this document, such compliance is not a warranty and is based solely on Epicor's current understanding of such laws
and requirements. All laws and requirements are subject to varying interpretations as well as to change and accordingly
Epicor cannot guarantee that the software will be compliant and up to date with such changes. All statements of
platform and product compatibility in this document shall be considered individually in relation to the products referred
to in the relevant statement, i.e., where any Epicor software is stated to be compatible with one product and also
stated to be compatible with another product, it should not be interpreted that such Epicor software is compatible
with both of the products running at the same time on the same platform or environment. Additionally platform or
product compatibility may require the application of Epicor or third-party updates, patches and/or service packs and
Epicor has no responsibility for compatibility issues which may be caused by updates, patches and/or service packs
released by third parties after the date of publication of this document. Epicor® is a registered trademark and/or
trademark of Epicor Software Corporation in the United States, certain other countries and/or the EU. All other
trademarks mentioned are the property of their respective owners. Copyright © Epicor Software Corporation 2014.
All rights reserved. No part of this publication may be reproduced in any form without the prior written consent of
Epicor Software Corporation.

Revision: September 05, 2014 7:43 a.m.


Total pages: 38
install_E10.ditaval
Converted Code Programming Guide Contents

Contents
1 Introduction.........................................................................................................................5
2 Custom Code Conversion Guidelines.................................................................................5
2.1 ERP and ICE Tables.....................................................................................................................................5
2.2 Case Sensitivity..........................................................................................................................................6
2.2.1 Case Sensitivity in String Comparisons.............................................................................................6
2.2.2 Compilation Errors...........................................................................................................................6
2.3 Calling Method From Business Object........................................................................................................7
2.4 Accessing ERP Context From Within System Directive.................................................................................8
2.5 Throwing Exceptions..................................................................................................................................9
2.6 Calling Method From Standard Assembly...................................................................................................9
2.7 Compatibility Class..................................................................................................................................10
2.8 Replacing Resulting Dataset.....................................................................................................................11
2.9 Redundant Transaction Scope..................................................................................................................11
2.10 BufferCopy Considerations....................................................................................................................12
2.11 Working With Extended Data.................................................................................................................12
2.11.1 Create User-Defined Fields...........................................................................................................12
2.11.2 Access User-Defined Fields...........................................................................................................14
2.11.3 Loading Extended Data Into Various Objects................................................................................15
2.11.4 Transition Path.............................................................................................................................15
2.12 Obsolete ABL Code................................................................................................................................16
2.13 Migrating ABL Expressions.....................................................................................................................16
2.14 Using External Libraries..........................................................................................................................17
2.14.1 Create Project in Visual Studio.....................................................................................................17
2.14.2 Call External Assembly Using BPM...............................................................................................18
2.15 Debugging Using Visual Studio..............................................................................................................20
2.15.1 Locate BPM Sources.....................................................................................................................20
2.15.2 Download Debugging Project......................................................................................................20
2.15.3 Open Project in Visual Studio.......................................................................................................21
2.15.4 Create Custom Code Directive.....................................................................................................22
2.15.5 Compile the Project.....................................................................................................................24
2.15.6 Debug the BPM...........................................................................................................................25
2.15.7 How to Modify Sample Project.....................................................................................................27
2.16 Adding and Subtracting Date.................................................................................................................28
2.17 Subtracting Two Dates and Comparing to an Integer Value....................................................................28
2.18 ABL Find Last Conversion.......................................................................................................................28
2.19 Using Unassigned Local Variable Message..............................................................................................30
2.20 Epicor 10 Equivalent to Row Mod = A or U............................................................................................31
2.21 Displaying an Informational Message.....................................................................................................31
2.22 Converting a Number to a String in LINQ Expression..............................................................................31
2.23 Outputting Data to a File.......................................................................................................................32
2.24 Updating Database Tables......................................................................................................................33

Epicor ERP 10.0.700 3


Contents Converted Code Programming Guide

2.25 Sample of BPM calling a .p file and the final Epicor 10 version................................................................34
2.26 Sample of a BPM That Sends an Email....................................................................................................36

4 Epicor ERP 10.0.700


Converted Code Programming Guide Introduction

1 Introduction

The Custom Code Conversion Utility converts snippets of Progress ABL code used in previous Epicor ERP releases
to .NET C# language used by the Epicor ERP 10 framework.
The primary goal of this utility is to support migration of customizations and BPM custom code conversions. The
purpose of this guide is to provide guidelines on what corrections and modifications users may need to perform
after the code is converted from ABL language to C#.
Note
You can access the conversion tool by clicking this link: https://scrs.epicor.com/ABLConversionweb/.
On the Log in dialog, enter your EPICweb or other assigned User Name and Password. Click Login.

This guide is available for download from the following locations:


• Custom Code Conversion Utility > About section
• ERP 10 Application Help under System Management > Business Process Management > Working With Business
Process Management section.
• EPICweb Products > Epicor ERP version 10 > Documentation
Important This guide is not intended to be a C# tutorial, it only provides tips on how to make your custom
code work in the Epicor ERP 10 framework. It also provides recommendations on how to write code in
BPM custom actions.

2 Custom Code Conversion Guidelines

2.1 ERP and ICE Tables

Epicor programs belong to either the application system (ERP) or the tools system (ICE). In Epicor ERP 10, certain
schema changes were made. Sometimes conversion results may need to be adjusted to reference the correct
part of the Epicor application.
In the following example, a user-defined table reference needs to be changed from "ERP" to "ICE", where it
now belongs.
Erp.Tables.UD01 UD01;
The updated code should look like the following:
Ice.Tables.UD01 UD01;

Epicor ERP 10.0.700 5


Custom Code Conversion Guidelines Converted Code Programming Guide

2.2 Case Sensitivity

2.2.1 Case Sensitivity in String Comparisons

By default, code written in C# treats string comparisons as case sensitive, which was not the case in ABL code.
String comparisons at the SQL server disregard the case, because the SQL server database is always set up as
case insensitive. The code converter attempts to compare two strings - string A and string B - using the following
code:
string.Compare(string A, string B, true)==0
Sometimes converted code's case is not accurate and must be adjusted manually. Also, when new custom code
is created, appropriate case must be taken into account.
string.Compare((string)ttJobHead_xRow["ShortChar02"], “Education”, true)!=0

2.2.2 Compilation Errors

Remember that C# is a case-sensitive language, and it may result in compilation errors. For example, look at the
simple below:
Notice that the error message has "customer" starting with a lower-case letter c.

This query will cause the following error message when you try to compile the BPM:

6 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

In order for the BPM to compile without errors, change the first line of the query to use an upper-case letter C
as shown below:

2.3 Calling Method From Business Object


In some cases, you need to call a method from a business object (BO). For this purpose, use the ServerRenderer
and add a reference to the contract containing the particular business object. ServerRenderer is a helper class
residing in Epicor.System.dll. You can use this class to make calls to any application service with the defined
contract. This class returns an instance of the contract, which you can use to invoke any method available on the
contract.
The signature of the method is displayed below:

In the following example, the GetByID() method is called from the Tip Service. In order to make a call to the
TipService method from another directive, you first add TipService contract assembly to the reference, and then
make the call. The svc variable holds the Tip contract instance.

If within one code scope (for example, one action) several calls are made to the same contract, it is recommended
to call ServiceRenderer just once. For example:

Epicor ERP 10.0.700 7


Custom Code Conversion Guidelines Converted Code Programming Guide

The following example displays a correct conversion of ABL code to C#.


• ABL Code:

• C# Code:

2.4 Accessing ERP Context From Within System Directive

You can access Erp Context from within a system directive. For example, review the following code:

In a BPM directive created for system BO "UD10", you need to access Part table which belongs to Erp context.
The code should look like the following:

Note At the moment, the BPM context is either ErpContext (for application directives) or IceContext (for
system directives). Therefore, within the IceContext, you will not find certain ERP tables (for example, Part),
and you will need to use the process described above.
Epicor is working towards enhancing the BPM and making the default context unified. Once this is
implemented, the need of accessing another context within the BPM code will be eliminated.

8 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2.5 Throwing Exceptions

Exceptions are used to indicate that an error has occurred while the program is running.
The following example displays how you can throw a business exception from within the code:
throw new Ice.BLException("My exception");
Note Within the BPM Workflow Designer, the Raise Exception workflow element is the preferred way of
throwing exceptions.

2.6 Calling Method From Standard Assembly

Use the following steps when calling a method from another assembly (non-external assembly).

1. Add a Reference to required assemblies:

2. Add the necessary Using clauses:

Epicor ERP 10.0.700 9


Custom Code Conversion Guidelines Converted Code Programming Guide

3. You can now construct the code that calls a method from another assembly. For example:

2.7 Compatibility Class

If the Compatibility class is present in the converted code, you need to add a reference to Compatibility.dll, which
can be found in the Assemblies folder.
This class contains conversion routines and helper methods to comply with Progress ABL code functionality.
• ABL Code:

• C# Code:

10 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2.8 Replacing Resulting Dataset

The following topic describes how to replace your directive's resulting record with another record.
For example, you may have a method directive action on the GetByID() method which returns a Part ID. The usual
BPM procedure provides the directive code with retrieved Part record, which is held in the ttPart table. If, for
some reason, you want to replace the whole resulting record with another record that you may have retrieved
yourself using another method, then you have the following options:
• Set the values on ttPart
• Replace the whole dataset
Note Fetching the dataset and replacing the whole dataset using the Attach method eliminates the need
of writing a lot of code. This is especially useful when the resulting dataset contains several tables.

In the following example, the record is retrieved using a sample method FetchRecord() and the result is replaced
with myRec.
var myRec = myService.FetchRecord(id);
this.dsHolder.Attach(myRec);

2.9 Redundant Transaction Scope

Usually using the Transaction Scope is not required as it is handled by the base method such as Update(). In some
cases, the code converter adds an unnecessary Transaction Scope reference, which needs to be manually removed.
For example, this behaviour may occur when you have a join between a temp table and a database table:
• ABL Code:

• Converted C# Code:

In this example, to fix the code above, remove the highlighted lines.

Epicor ERP 10.0.700 11


Custom Code Conversion Guidelines Converted Code Programming Guide

2.10 BufferCopy Considerations

BufferCopy is used to copy from source buffer to target buffer.


For example, in the below declaration, the b2 reference is not initialized:
BufferCopy .CopyExceptFor(b1, b2)
The declaration of b2 then looks like the following:
Erp.Tables.Part b2;
As a resolution, correct the declaration as following:
Erp.Tables.Part b2 = new Erp.Tables.Part();
If BufferCopy is used in a loop, then b2 needs to be assigned a new instance on each iteration, otherwise it will
lose the values from the previous iteration.

2.11 Working With Extended Data

The following section describes what you should consider when working with Extended Data and the process of
creating custom columns and their usage within the BPM functionality.
In the previous versions of the Epicor application, each table included a series of user-defined fields, such as
Character01, Date03, Number02. While these additional columns were mostly sufficient for customizations,
some users ran out of available columns. Then, during an upgrade, these user-defined fields were overwritten,
so users needed to export customizations and, after the upgrade was complete, import them back into the
application. This process sometimes required users to additionally update the tables/columns to make the
customization compatible with the new application version. In other Epicor installations, the predefined user-defined
columns might not have been used at all, and were causing unnecessary system load.
To address these issues, the Epicor application now incorporates this functionality as a database extension. If you
are building a BPM directive that needs unique fields, you create extended user-defined tables and add columns
to these tables. Since these tables are extensions from parent tables, they are not overwritten during an upgrade.

2.11.1 Create User-Defined Fields

In Epicor ERP 10, use the following process to create extended user-defined fields.
Note The existing Epicor 9.05 user-defined columns that were utilized (contained data) are automatically
migrated to Epicor ERP 10 as extended data columns.

1. Create the extended user-defined tables and columns (fields) within the Epicor application. To do this,
navigate to System Setup > System Maintenance and open Extended User Defined Table Maintenance.

2. Find and select the table you need to extend. Click Save. The application adds a "_UD" suffix to the end
of the table identifier.

3. Add the needed custom columns to the extended user-defined table that you have created.

12 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

When you save each column, the application adds a "_c" suffix to the end of this table column. This suffix
will help you identify this custom column when you create BPM directives that reference this column.

4. Add the extended user-defined table to the database. To do this, link it to the database by clicking the
Actions menu and selecting either the Sync Current Table to the DB or Sync All Tables to DB option.

5. Regenerate the data model for the Epicor database. You or your system administrator runs this task on the
server that hosts your database. The data model is regenerated using the Epicor Administration Console.
As a result, the base and the user-defined tables are joined in the data model.

6. Pull the latest data model from the database and copy it to the local application server by restarting IIS.
After the data model is successfully regenerated, restart the IIS.
Important Do not skip this step!

Note Unlike previous versions of the Epicor application, running the Directive Update program and
Refreshing Signatures of directives referencing affected table(s) with UD columns is no longer needed,
as it is performed automatically.

The extended user defined table and columns are now fully integrated with the database. You can now monitor
and update these custom columns through BPM directives.

Epicor ERP 10.0.700 13


Custom Code Conversion Guidelines Converted Code Programming Guide

2.11.2 Access User-Defined Fields

This topic describes how you can reference user-defined columns within BPM in Epicor ERP 10.

1. User defined tables and primary tables merge into one for the database context. When you construct a Data
or Method Directive workflow, user-defined columns display as part of the base table.

2. When you design a business activity query (BAQ) in BPM from within Data and Method Directives, user-defined
columns also appear as part of the base table.

3. When working with ttTables for Data Directives, user-defined fields appear as part of the primary table,
and can be directly accessed. For example:
ttABCCode.MyNewColumn_c

4. Method directives work with temporary (tt) tables using tablesets, and so you access them through different
syntax. These tablesets are defined in the business object's (BO) contract .dll file, so their format is fixed and
they are not regenerated with the data model. When building a method directive that refers to user-defined
fields in temporary tables, reference them using the <tablename>["UDField<>()"] syntax. For example:
ttABCCode.UDField<System.String>(" MyNewColumn _c")

14 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2.11.3 Loading Extended Data Into Various Objects

This topic discusses available extensions you can use to load ExtendedData into various objects.
Note Extended data is loaded automatically into table entities when data is retrieved from the database.
You may only need to manually load extended data into IceTablesets, IceTables or IceRow. Examples are
below:

• IceRow:
Ice.Tablesets.TipRow iceRow = new TipRow();

iceRow.LoadExtendedData(Db);

• IceTable:
Ice.Tablesets.TipTable iceTable = new TipTable();

iceTable.LoadExtendedData(Db);

• List<IceRow>:
List<IceRow> list = new List<IceRow>();

list.LoadExtendedData(Db);

• IceTableset:
Ice.Tablesets.TipTableset ts = new TipTableset();

ts.LoadExtendedData(Db);

2.11.4 Transition Path

This topic explains actions you need to take when you migrate UD Fields from Epicor ERP 10 Beta code prior to
10.0.600 into Epicor ERP version 10.0.600 or later.
Note You only need to perform the following steps if you are migrating from Epicor ERP 10 Beta prior to
version 10.0.600.

1. As part of the installation process, Regeneration of the Data Model is performed. This ensures the UD fields
are included in the data model.

2. The next step involves running mandatory BPM conversion. The conversion process upgrades BPM directives
to follow the new extended data approach.

3. After you log into the application, Epicor recommends to review the following:
• BPM directives that have become Outdated (as it is usual when upgrading from older builds)
• BPM directives that are known to contain UD Field references in queries or custom codes. It is highly
recommended to review these directive to ensure their performance is optimized in the new environment.

Epicor ERP 10.0.700 15


Custom Code Conversion Guidelines Converted Code Programming Guide

Example
• Previously for database queries a join between the extended table and base table was used, for
example:
Ice.Tip join Ice.Tip_UD on t.SysRowID = tu.ForeignSysRowID
The migration process is likely to convert such code as follows:
Ice.Tip join Ice.Tip_UD on t.SysRowID = tu.SysRowID
If the above code compiles, it is sub-optimal. Because the data model now merges Extended Table
columns with the respective base table automatically, you should refer to the Tip entity object only
to eliminate references or joins to Tip_UD altogether.
• Custom code performing [loop on Tip from the DB] with inner [loop on Tip_UD from the DB]
This code will be converted to [loop on Tip from the DB] with inner [loop on Tip from the DB]. The
most optimal way is [loop on Tip from the DB], however the body of the loop will need to be
adjusted.

4. When importing BPM directives referencing UD fields created in the code prior to 10.0.600, these directives
are also automatically converted and should be reviewed for optimal performance.

2.12 Obsolete ABL Code

Certain calls that existed in Epicor 9.05 became obsolete in Epicor ERP 10. They need to be removed from the
source code or the converted code.
For example, you may have an Epicor 9.05 BPM directive that uses an ABL action with code that calls
lib\UpdateTableBuffer.p.
To avoid compilation errors when converting such directive, remove the below call from either the original source
code snippet, or from the converted code:
lib\UpdateTableBuffer.p

2.13 Migrating ABL Expressions

The BPM Migration Tool is capable of migrating most of the valid Epicor 9.05 ABL expressions.
To ensure a successful migration of expressions, verify the following:
• ABL expressions are functional in your Epicor 9.05 application.
• All tables, arguments and functions used in expressions are known.

16 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2.14 Using External Libraries

Please consider the following information when selecting the approach for migrating external .p routines from
Epicor 9.05 to Epicor ERP 10.
In certain cases when Epicor 9.05 customizations contained many calls to external .p progress code files, it may
be reasonable to combine these .p routines into a single .NET assembly (library) of external methods. These
methods can then be called from within a BPM flowchart using the Invoke External Method BPM element.
You can also consider creating an external library, when you called a method in the Epicor 9.05 external .p file,
which subsequently invoked other methods within the same or different .p code files.
However, if the external .p contained simple code in one or few methods, it is recommended to convert such
code into a snippet and incorporate it into the BPM Execute Custom Code element, rather than creating an
external library assembly. Please note that this approach may be preferred as:
• It does not require .NET Visual Studio
• It does not require maintaining and updating external assemblies

2.14.1 Create Project in Visual Studio

The following section describes how to create a new project using the Visual Studio.
In the example below, the project utilizes the Update Method Directive for Tip Service.

1. Create an empty C# Class Library Type Project. In this example, we create the project called "ExternalBpm".

2. Add the following references from the Server Assemblies Folder:

Note that the Ice.Contracts.BO.Tip is added, as we are going to make a call from Tip Update BPM Method
Directive.

Epicor ERP 10.0.700 17


Custom Code Conversion Guidelines Converted Code Programming Guide

Important Make sure to set "Copy Local=False" for all added references.

3. The project adds the Class by default. You can rename it, if you want. In this example, MyTip.cs is used.

2.14.2 Call External Assembly Using BPM

1. In your Epicor EPM 10 application, open Method Directives. To do this, navigate to System Management
> Business Process management > Method Directives Maintenance.

2. Locate the Ice.Tip.Update method.

3. From the Actions menu, select Create Programming Interface.

4. The Programming Interface Generator Form window displays the method signature.

5. Copy the whole code (or method, if you already have other methods there).

6. Add your logic into the method and compile the project.

7. Place the library assembly file to the folder for external assemblies. Usually, it is the folder located within
the Server\Customization\Externals folder, but this setting can be changed in the application's
web.config, within the CustomizationSettings property.

18 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

8. You can now use this library and call it using the Invoke External Method workflow element.

9. Select the external assembly by clicking the external link.

10. Select the method using the specified method link.

Epicor ERP 10.0.700 19


Custom Code Conversion Guidelines Converted Code Programming Guide

The external Update method from ExternalBpm assembly will now be called by the BPM.
Tip For more detailed example, review the Custom Business Process Management chapter found
within the Epicor ICE 3.0 Tools User Guide.

2.15 Debugging Using Visual Studio

If you have Microsoft® Visual Studio™ 2010 or higher, you can debug execution of custom code directives.
Debugging can be particularly useful when you need to review execution of a complex custom code.
Important This section provides details on how you can set up a debugging project. The example that
follows demonstrates how to debug the Tip.Update directive sample delivered by Epicor. In your environment,
you can apply the following steps on another directive. For more info on custom project debugging, see
the How to Modify Sample Project topic at the end of this section.

2.15.1 Locate BPM Sources

In your Epicor ERP installation, locate the BPM Sources folder. By default, Sources are found in the BPM folder
of the Server directory.

2.15.2 Download Debugging Project

Download the project used for debugging.

1. In the Conversion Utility, select the About web page.

20 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2. Click the Wrapper Project for debugging link.

3. Download the zipped file.

4. Extract the project folder from zip archive into the BPM > Sources directory.

Important Relative paths in the project file assume that the BPM subfolder is located directly under
the Server deployment folder. If this is not the case, change the relative paths manually from the Visual
Studio to point to the location of Server\Bin or server\Assemblies folders.

2.15.3 Open Project in Visual Studio

For the next step, open the downloaded project in Visual Studio.
The below sample project is configured for Tip.Update directive. Notice the following settings specific to the
Tip.Update sample:
• The contract for Tip service displays within references.

Epicor ERP 10.0.700 21


Custom Code Conversion Guidelines Converted Code Programming Guide

• The TipUpdate folder contains 3 files generated by BPM.

• The namespace and assembly name is set to Ice.Bpm.Tip.Update.

2.15.4 Create Custom Code Directive

Use Method Directives to create a custom code directive for the Tip.Update Pre-Processing method.
In this sample a simple code checks if Tip Title is "A" and then updates the TipText with a string "Tip Text from
BPM".

1. Navigate to Method Directives.


System Management > Business Process Management > Method Directives Maintenance

22 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2. Locate the Ice.Tip.Update method.

3. Use the BPM Workflow Designer to construct a simple BPM workflow.

4. Drag and drop the Execute Custom Code workflow item in the design area.

5. The following code is used in the Execute Custom Code item:

6. Connect Start to Execute Custom Code.

7. Click Save and Enable the directive.

8. The BPM generates source files in Server\BPM\Sources\BO\Tip.Update folder.

Epicor ERP 10.0.700 23


Custom Code Conversion Guidelines Converted Code Programming Guide

Note The folder may contains multiple revisions - take files from the latest one and copy them into
the project's TipUpdate folder.

2.15.5 Compile the Project

The next step is to compile the project in Visual Studio and attach the debugger to the ASP process.

1. Compile the project.


You may need to reset the server application using IIS Reset or tweak the web.config.

2. Set the breakpoint in the custom code found in the Tip.Update.cs file.

24 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

3. Start the Epicor ERP client and attach the debugger to the ASP process.

2.15.6 Debug the BPM

Fire the BPM and view the code execution in the debugger.

1. Launch the Tip of the Day Maintenance form.


System Setup > System Maintenance > Tip Of the Day

2. Create a new record.

Epicor ERP 10.0.700 25


Custom Code Conversion Guidelines Converted Code Programming Guide

3. In the Title field, enter A and click Save.

4. At this point the debugger stops at the specified break point and you can the follow code execution, examine
variable values and so on.

26 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

5. Based on the custom code defined in Method Directives, the BPM populates the Tip text value.

2.15.7 How to Modify Sample Project

You can modify the sample project to debug another directive from another service.
Follow these steps to perform custom debugging:
• Create your custom directive.
• Create a new folder in the project similar to TipUpdate; based on the selected directive.
• Locate the sources generated by BPM and copy to this folder.

Epicor ERP 10.0.700 27


Custom Code Conversion Guidelines Converted Code Programming Guide

• Locate the assembly generated by the BPM and name the project assembly the same.
The assemblies generated by BPM are found in Server\Customizations\BO folder.

2.16 Adding and Subtracting Date

To add or subtract days from a given date field, use the syntax as displayed below. Note that subtraction is done
by adding a negative number of days
In the following example, 6 days are substracted from NeedByDate:
ttOrderHedRow.NeedByDate.Value.AddDays(-6)

2.17 Subtracting Two Dates and Comparing to an Integer Value

Use the following syntax to subtract one date from another and then compare the number of days difference to
an integer value.
Difference and Days are variable names and can be replaced with any variable name of your choice.
var difference = DateTime.Today - PartTran.TranDate;
var days = difference.Value.Days;
if ( days > 90)

2.18 ABL Find Last Conversion

This topic discusses manual code adjustments after the Conversion Utility processes an ABL Find Last statement.
Assume the below statement exists in a BPM.

28 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

The above statement is converted by the utility as follows:

Now specify an OrderBy clause to sort the data. In this example, the last record becomes the first record in the
returned rows:

Epicor ERP 10.0.700 29


Custom Code Conversion Guidelines Converted Code Programming Guide

2.19 Using Unassigned Local Variable Message

Within the BPM logic, it may happen that a variable is not set. In that case, the compiler displays an error message,
reporting use of an unassigned local variable.
Review the following example:

This code will generate the following error upon compilation:


Server Side Exception
There is at least one compilation error.
Exception caught in: Epicor.ServiceModel
Error Detail
============
Description: There is at least one compilation error.
Details:
Error CS0165: Use of unassigned local variable 'Customer_UD'
Notice that in the code example, the Customer_UD variable is only set when the following condition is met:
if (Customer != null)
You can correct the error by changing the second line of the example to:
Erp.Tables.Customer_UD Customer_UD = null;
This change ensures that the variable gets set to some value regardless of the IF statement.

30 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2.20 Epicor 10 Equivalent to Row Mod = A or U

In many BPMs a user wants to perform a certain action if the tt record is a new record or updated record. In
Epicor 9.05 the status of the RowMod = 'A' or 'U' was used in this case. The Epicor 10 equivalent is displayed
below:

2.21 Displaying an Informational Message

Informational messages are useful when debugging BPMs and presenting non-exception type messages to the
users.
You can publish an informational message to the user from the execute custom code node in the BPM designer.
The syntax example is shown below:

The last two parameters are optional, you can leave the strings empty.
Note that the possible values for message type are: Information, Question, Warning, Error, UpdateConflict. The
possible values for the InfoMessageDisplayMode are: Individual & Grid.
Example message was placed in vMiscInfo variable. Note that you should not use all capitalized "BPM" in the
reference to the Display Mode parameter, it should be "Bpm".

2.22 Converting a Number to a String in LINQ Expression

Review an example of a LINQ query below:

You may receive the following exception error at runtime:


Server Side Exception
LINQ to Entities does not recognize the method 'System.String ToString()' metho

Epicor ERP 10.0.700 31


Custom Code Conversion Guidelines Converted Code Programming Guide

d, and this method cannot be translated into a store expression.


Exception caught in: Epicor.ServiceModel
Error Detail
============
Description: LINQ to Entities does not recognize the method 'System.String ToS
tring()' method, and this method cannot be translated into a store expression.
Program: System.Data.Entity.dll
Method: Translate
Original Exception Type: NotSupportedException
The corrected code looks like the following:

You should also add the using reference below in the BPM Designer > Usings tab:
using System.Data.Objects.SqlClient;

2.23 Outputting Data to a File

The syntax shown below can be used for BPMs that write data out to a file. You can create a new file as in the
example below, or replace Create with Append to append to an existing file.

The relevant syntax is highlighted in the example below:

32 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

2.24 Updating Database Tables

The Upgrade Conversion Programmer's Guide recommends removing redundant scoping for database updates.
This is usually done due to the fact that the scoping in the BPM from the conversion tool will be promoted up
to the Method the BPM is associated with. The reason we do this is because we do not want anyone to be able
to update the record in the table before we do since we use optimistic locking and could run into concurrency
issues without it. If we are in a BPM on an update method, this scope may be promoted to the Update method
scope, but it is still a good idea to include them as good programming practice.
The example below shows how to scope the transaction for updating the InvcDetail_UD table's Number 01 field.
The Using statement starts the transaction, the Db.Validate statement does the update, and the txscope statement
ends the transaction. Note that the select query adds a With(LockHint.UpdLock) phrase to the select statement
for the table we are going to update (the InvcDtl_UD table in this example).

Epicor ERP 10.0.700 33


Custom Code Conversion Guidelines Converted Code Programming Guide

2.25 Sample of BPM calling a .p file and the final Epicor 10 version

Epicor 9.05, ABL Code was calling a .p file that called the UD14 business object and added certain data to it. In
Epicor 10, the BPM was modified to call the business objects and the .p code moved into the BPM's Execute
Custom Code action.
• Epicor 9.05 ABL Code:

• Epicor 9.05 .P Files Contents:

34 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

• Final Epicor 10 C# Code that Compiled in BPM designer:

Epicor ERP 10.0.700 35


Custom Code Conversion Guidelines Converted Code Programming Guide

2.26 Sample of a BPM That Sends an Email

In Epicor 9.05, it was possible to send emails via ABL code without using any of the BPM wizards. The same
functionality equivalent for Epicor 10 is shown below:

36 Epicor ERP 10.0.700


Converted Code Programming Guide Custom Code Conversion Guidelines

Epicor ERP 10.0.700 37


Additional information is available at the Education and
Documentation areas of the EPICweb Customer Portal. To access
this site, you need a Site ID and an EPICweb account. To create an
account, go to http://support.epicor.com.

You might also like