Epicor10 C

38
Converted Code Programming Guide Epicor ERP 10.0.700

description

epicor

Transcript of Epicor10 C

Page 1: Epicor10 C

Converted Code Programming GuideEpicor ERP 10.0.700

Page 2: Epicor10 C

Disclaimer

This document is for informational purposes only and is subject to change without notice. This document and itscontents, including the viewpoints, dates and functional content expressed herein are believed to be accurate as of itsdate of publication. However, Epicor Software Corporation makes no guarantee, representations or warranties withregard to the enclosed information and specifically disclaims any applicable implied warranties, such as fitness for aparticular purpose, merchantability, satisfactory quality or reasonable skill and care. As each user of Epicor software islikely to be unique in their requirements in the use of such software and their business processes, users of this documentare always advised to discuss the content of this document with their Epicor account manager. All information containedherein is subject to change without notice and changes to this document since printing and other important informationabout the software product are made or published in release notes, and you are urged to obtain the current releasenotes for the software product. We welcome user comments and reserve the right to revise this publication and/ormake 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 ofany consulting services by Epicor personnel shall be pursuant to Epicor's standard services terms and conditions. Usageof the solution(s) described in this document with other Epicor software or third party products may require the purchaseof licenses for such other products. Where any software is expressed to be compliant with local laws or requirementsin this document, such compliance is not a warranty and is based solely on Epicor's current understanding of such lawsand requirements. All laws and requirements are subject to varying interpretations as well as to change and accordinglyEpicor cannot guarantee that the software will be compliant and up to date with such changes. All statements ofplatform and product compatibility in this document shall be considered individually in relation to the products referredto in the relevant statement, i.e., where any Epicor software is stated to be compatible with one product and alsostated to be compatible with another product, it should not be interpreted that such Epicor software is compatiblewith both of the products running at the same time on the same platform or environment. Additionally platform orproduct compatibility may require the application of Epicor or third-party updates, patches and/or service packs andEpicor has no responsibility for compatibility issues which may be caused by updates, patches and/or service packsreleased by third parties after the date of publication of this document. Epicor® is a registered trademark and/ortrademark of Epicor Software Corporation in the United States, certain other countries and/or the EU. All othertrademarks 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 ofEpicor Software Corporation.

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

Total pages: 38

install_E10.ditaval

Page 3: Epicor10 C

Contents

1 Introduction.........................................................................................................................52 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

3Epicor ERP 10.0.700

ContentsConverted Code Programming Guide

Page 4: Epicor10 C

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

Epicor ERP 10.0.7004

Converted Code Programming GuideContents

Page 5: Epicor10 C

1 Introduction

The Custom Code Conversion Utility converts snippets of Progress ABL code used in previous Epicor ERP releasesto .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. Thepurpose of this guide is to provide guidelines on what corrections and modifications users may need to performafter 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 BusinessProcess 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 customcode work in the Epicor ERP 10 framework. It also provides recommendations on how to write code inBPM 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, certainschema changes were made. Sometimes conversion results may need to be adjusted to reference the correctpart of the Epicor application.

In the following example, a user-defined table reference needs to be changed from "ERP" to "ICE", where itnow belongs.

Erp.Tables.UD01 UD01;

The updated code should look like the following:

Ice.Tables.UD01 UD01;

5Epicor ERP 10.0.700

IntroductionConverted Code Programming Guide

Page 6: Epicor10 C

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 ascase insensitive. The code converter attempts to compare two strings - string A and string B - using the followingcode:

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 codeis 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 thesimple 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:

Epicor ERP 10.0.7006

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 7: Epicor10 C

In order for the BPM to compile without errors, change the first line of the query to use an upper-case letter Cas 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 ServerRendererand add a reference to the contract containing the particular business object. ServerRenderer is a helper classresiding in Epicor.System.dll. You can use this class to make calls to any application service with the definedcontract. This class returns an instance of the contract, which you can use to invoke any method available on thecontract.

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 theTipService method from another directive, you first add TipService contract assembly to the reference, and thenmake 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 recommendedto call ServiceRenderer just once. For example:

7Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 8: Epicor10 C

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 (forsystem 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 isimplemented, the need of accessing another context within the BPM code will be eliminated.

Epicor ERP 10.0.7008

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 9: Epicor10 C

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 ofthrowing 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:

9Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 10: Epicor10 C

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, whichcan 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:

Epicor ERP 10.0.70010

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 11: Epicor10 C

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 usualBPM procedure provides the directive code with retrieved Part record, which is held in the ttPart table. If, forsome reason, you want to replace the whole resulting record with another record that you may have retrievedyourself 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 needof 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 replacedwith 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 somecases, 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.

11Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 12: Epicor10 C

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 willlose 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 ofcreating 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 asCharacter01, 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 theapplication. This process sometimes required users to additionally update the tables/columns to make thecustomization compatible with the new application version. In other Epicor installations, the predefined user-definedcolumns 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 youare building a BPM directive that needs unique fields, you create extended user-defined tables and add columnsto 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 automaticallymigrated 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 endof the table identifier.

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

Epicor ERP 10.0.70012

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 13: Epicor10 C

When you save each column, the application adds a "_c" suffix to the end of this table column. This suffixwill 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 theActions 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 theserver 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 andRefreshing 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 monitorand update these custom columns through BPM directives.

13Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 14: Epicor10 C

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 Dataor 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-definedcolumns 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 differentsyntax. These tablesets are defined in the business object's (BO) contract .dll file, so their format is fixed andthey are not regenerated with the data model. When building a method directive that refers to user-definedfields in temporary tables, reference them using the <tablename>["UDField<>()"] syntax. For example:

ttABCCode.UDField<System.String>(" MyNewColumn _c")

Epicor ERP 10.0.70014

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 15: Epicor10 C

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 arebelow:

• 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 to10.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 toversion 10.0.600.

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

2. The next step involves running mandatory BPM conversion. The conversion process upgrades BPM directivesto 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 highlyrecommended to review these directive to ensure their performance is optimized in the new environment.

15Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 16: Epicor10 C

Example

• Previously for database queries a join between the extended table and base table was used, forexample:

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 Tablecolumns with the respective base table automatically, you should refer to the Tip entity object onlyto 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]. Themost optimal way is [loop on Tip from the DB], however the body of the loop will need to beadjusted.

4. When importing BPM directives referencing UD fields created in the code prior to 10.0.600, these directivesare 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 thesource code or the converted code.

For example, you may have an Epicor 9.05 BPM directive that uses an ABL action with code that callslib\UpdateTableBuffer.p.

To avoid compilation errors when converting such directive, remove the below call from either the original sourcecode 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.

Epicor ERP 10.0.70016

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 17: Epicor10 C

2.14 Using External Libraries

Please consider the following information when selecting the approach for migrating external .p routines fromEpicor 9.05 to Epicor ERP 10.

In certain cases when Epicor 9.05 customizations contained many calls to external .p progress code files, it maybe reasonable to combine these .p routines into a single .NET assembly (library) of external methods. Thesemethods 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 suchcode into a snippet and incorporate it into the BPM Execute Custom Code element, rather than creating anexternal 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 MethodDirective.

17Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 18: Epicor10 C

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 withinthe Server\Customization\Externals folder, but this setting can be changed in the application'sweb.config, within the CustomizationSettings property.

Epicor ERP 10.0.70018

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 19: Epicor10 C

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.

19Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 20: Epicor10 C

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 foundwithin 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 thatfollows 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, seethe 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 folderof 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.

Epicor ERP 10.0.70020

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 21: Epicor10 C

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 underthe Server deployment folder. If this is not the case, change the relative paths manually from the VisualStudio 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 theTip.Update sample:

• The contract for Tip service displays within references.

21Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 22: Epicor10 C

• 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 fromBPM".

1. Navigate to Method Directives.

System Management > Business Process Management > Method Directives Maintenance

Epicor ERP 10.0.70022

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 23: Epicor10 C

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.

23Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 24: Epicor10 C

Note The folder may contains multiple revisions - take files from the latest one and copy them intothe 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.

Epicor ERP 10.0.70024

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 25: Epicor10 C

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.

25Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 26: Epicor10 C

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, examinevariable values and so on.

Epicor ERP 10.0.70026

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 27: Epicor10 C

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.

27Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 28: Epicor10 C

• 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 doneby 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 toan 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.

Epicor ERP 10.0.70028

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 29: Epicor10 C

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 thereturned rows:

29Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 30: Epicor10 C

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 ExceptionThere is at least one compilation error.Exception caught in: Epicor.ServiceModelError 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.

Epicor ERP 10.0.70030

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 31: Epicor10 C

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. InEpicor 9.05 the status of the RowMod = 'A' or 'U' was used in this case. The Epicor 10 equivalent is displayedbelow:

2.21 Displaying an Informational Message

Informational messages are useful when debugging BPMs and presenting non-exception type messages to theusers.

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. Thepossible values for the InfoMessageDisplayMode are: Individual & Grid.

Example message was placed in vMiscInfo variable. Note that you should not use all capitalized "BPM" in thereference 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 ExceptionLINQ to Entities does not recognize the method 'System.String ToString()' metho

31Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 32: Epicor10 C

d, and this method cannot be translated into a store expression.Exception caught in: Epicor.ServiceModelError Detail ============Description: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression.Program: System.Data.Entity.dllMethod: TranslateOriginal 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 theexample below, or replace Create with Append to append to an existing file.

The relevant syntax is highlighted in the example below:

Epicor ERP 10.0.70032

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 33: Epicor10 C

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 upto the Method the BPM is associated with. The reason we do this is because we do not want anyone to be ableto update the record in the table before we do since we use optimistic locking and could run into concurrencyissues without it. If we are in a BPM on an update method, this scope may be promoted to the Update methodscope, 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 statementends the transaction. Note that the select query adds a With(LockHint.UpdLock) phrase to the select statementfor the table we are going to update (the InvcDtl_UD table in this example).

33Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 34: Epicor10 C

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. InEpicor 10, the BPM was modified to call the business objects and the .p code moved into the BPM's ExecuteCustom Code action.

• Epicor 9.05 ABL Code:

• Epicor 9.05 .P Files Contents:

Epicor ERP 10.0.70034

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 35: Epicor10 C

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

35Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 36: Epicor10 C

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 samefunctionality equivalent for Epicor 10 is shown below:

Epicor ERP 10.0.70036

Converted Code Programming GuideCustom Code Conversion Guidelines

Page 37: Epicor10 C

37Epicor ERP 10.0.700

Custom Code Conversion GuidelinesConverted Code Programming Guide

Page 38: Epicor10 C

Additional information is available at the Education andDocumentation areas of the EPICweb Customer Portal. To access

this site, you need a Site ID and an EPICweb account. To create anaccount, go to http://support.epicor.com.