Advanced Epicor Functions
Advanced Epicor Functions
EDE8511906
90521-10-9252-583101989
11.1
Revision: March 08, 2021 6:40 p.m.
Total pages: 43
course.ditaval
Advanced Epicor Functions Contents
Contents
Advanced Epicor Functions....................................................................................................5
Before You Begin....................................................................................................................6
Audience.........................................................................................................................................................6
Prerequisites....................................................................................................................................................6
Environment Setup..........................................................................................................................................7
Workshop Constraints..............................................................................................................................8
Functions Security Group Setup..........................................................................................10
Creating Custom Code in Functions....................................................................................12
Workshop - Create Custom Code Function....................................................................................................12
Create Library for Utility Functions..........................................................................................................12
Register Your App with ZipCodeAPI........................................................................................................13
Create Function......................................................................................................................................13
Add Function Code.................................................................................................................................14
Workshop - Create Widget Function with Custom Code................................................................................15
Create xxxCustLib Library........................................................................................................................15
Add Widget Function with Code.............................................................................................................16
Design Function Workflow......................................................................................................................17
Test Function..........................................................................................................................................19
Advanced Usage of Epicor Functions..................................................................................21
Workshop - Call Function from Another Function..........................................................................................21
Modify Library Settings and Function Signature.......................................................................................21
Invoke Function and Calculate Local Time...............................................................................................22
Workshop - Call Function from Client Customization.....................................................................................24
Add New UI Controls to Customer Maintenance.....................................................................................24
Add and Configure REST Client..............................................................................................................25
Full Script Code...............................................................................................................................27
Add Menu for Customized Program.......................................................................................................28
Invoke Function from Customization.......................................................................................................29
Database Access from Custom Code of Epicor Functions..................................................30
Advanced Function Administration.....................................................................................32
Workshop - Add Library to Solution...............................................................................................................32
Workshop - Install Function Library................................................................................................................34
Workshop - Schedule Function.......................................................................................................................35
Create Function to Manage Run Out Parts with Depleted Stock..............................................................35
Add New Part for Testing Function.........................................................................................................37
Create Schedule.....................................................................................................................................38
Schedule Function..................................................................................................................................38
Test Function Execution..........................................................................................................................39
Advanced Function Security................................................................................................40
Workshop - Add Function to an Access Scope................................................................................................40
Conclusion.............................................................................................................................42
This course focuses on the advanced features of Epicor Functions available to Functions Power Developers
and Functions Administrators.
Important Make sure that, for the purpose of this course, you establish the proper security setup in
accordance with instructions in the Functions Security Groups Setup topic.
This course contains a series of hands-on workshops that demonstrate how you can develop, use, and manage
Epicor Functions with more complex workflows that include custom code.
The course opens with the Creating Custom Code in Functions block, where as a Functions Power Developer,
you will use the Epicor Functions Maintenance program to create a Custom Code Function and a Widget
Function with Code.
The workshops of the Advanced Usage of Functions section provide examples of Function calls - from another
Function and from a client customization.
The Advanced Function Administration section contains workshops that provide detail on the advanced
features of Epicor Functions available to Functions Administrators: exporting a library into a solution, installing a
solution containing a Function library, and scheduling Function execution (available to all users).
The Database Access from Epicor Functions section explains how Functions Power Developers can set up
read-only or read-write access to database tables from their Function custom code.
In the Advanced Function Security section, you will learn how you can add a Function library to an Access
Scope.
Upon successful completion of this course, you will be able to:
• Understand advanced concepts of Epicor Functions.
• Create Widget Functions with Code and design their workflow with the help of the Function Designer.
• Create Custom Code Functions and add their code in the Function Editor.
• Call a Function from another Function.
• Call a Function from a client customization.
• Call a Function directly via scheduled execution by System Agent.
• Understand how you can access database from Functions' custom code.
• Add a Function library to a solution.
• Install a Function library.
• Add a Function library to an Access Scope.
Read this topic for information you should know in order to successfully complete this course.
Audience
Prerequisites
To complete the workshops in this course, the necessary modules must be licensed and operating in your training
environment. For more information on the modules available, contact your Epicor Customer Account Manager.
It is also important you understand the prerequisite knowledge contained in other valuable courses.
• Introduction to Epicor Functions Course - This course explains the basic capabilities provided by the Epicor
Functions framework. It focuses on the features and operations available to the two pre-set Functions-related
security groups - Functions Administrators and Functions Developers.
• Embedded Customization Course - This course explores the customization tools embedded within the
Epicor ERP application. Through the customization tools, users can add/remove data elements, modify
component properties, create custom C# code that runs before and after data field modifications, and other
modifications that better match the Epicor ERP application with the requirements of your business or industry.
• Advanced Embedded Customization Course - Through this course you will explore customization techniques
that go beyond the basics of text boxes and grids. It examines how to customize a program using the C#
programming language, introducing several wizards that help you generate custom C# code.
• Database Concepts Course - This course reviews the table and field name identification process using Field
Help, Customization Tools, and the Data Dictionary Viewer functionality. It also describes table linking
procedures and requirements as well as join type definitions and specifications.
• System Setup and Management Course - This course explores how you set up and manage the Epicor
ERP application. By understanding these tools, you control how users access and run the application as well
as manage automatic processes and customizations.
• Technical Knowledge
• Basic skills in C# programming
• Familiarity with the HTTP protocol and REST
• Industry Knowledge - Understanding the functionality of the current release of the Epicor ERP application.
Environment Setup
The environment setup steps and potential workshop constraints must be reviewed in order to successfully
complete the workshops in this course.
Your Epicor training environment, in which the Epicor demonstration database is found, enables you to experience
Epicor functionality in action but does not affect data in your live, production environment.
The following steps must be taken to successfully complete the workshops in this course.
1. Verify the following or ask your system administrator to verify for you:
• Your Epicor training icon points to your Epicor training environment with the Epicor demonstration
database installed. Do not complete the course workshops in your live, production environment. Note
It is recommended that multiple Epicor demonstration databases are installed. Contact Support or Systems
Consulting for billable assistance.
• The Epicor demonstration database is at the same version as the Epicor application. The demonstration
database is installed from the Epicor Administration Console using the "Add Demo Database" command
under Database Server. See Epicor ERP installation guides for details. If you are an Epicor Cloud ERP
customer (and have licensed embedded education), the demonstration database is installed for you.
• Your system administrator restored (refreshed) the Epicor demonstration database prior to starting this
course. The Epicor demonstration database comes standard with parts, customers, sales orders, and so
on, already defined. If the Epicor demonstration database is shared with multiple users (that is, the
database is located on a server and users access the same data, much like your live, production
environment) and is not periodically refreshed, unexpected results can occur. For example, if a course
workshop requires you to ship a sales order that came standard in the Epicor demonstration database,
but a different user already completed this workshop and the Epicor demonstration database was not
restored (refreshed), then you will not be able to ship the sales order. If you are an Epicor Cloud ERP
customer see section below.
2. In the Current password field, enter the User ID of the user you are asked to log in as, for example,
'nancy'.
3. In the New password field, enter a new password, for example 'Train123'.
Important In Epicor ERP Cloud environment, the password must not contain user ID, must be
longer than 7 characters and include at least one uppercase letter.
5. Click OK. The Change Password window closes and you are logged on with the new user ID.
Note Record the new password. This is important as this will be the password everyone uses
when they log on with this User ID, until the database is refreshed.
3. From the Main menu, select the company Epicor Education (EPIC06).
6. In the window that displays, in the Form To Use field, select Classic.
7. Select OK to confirm.
Note To refresh your Epicor training data, enter a support ticket in EpicCare and include your site ID.
Workshop Constraints
The workshops in this course can be performed only once in each instance of a restored (refreshed) shared
database. If a user has already completed these workshops in the database, the database must be restored
(refreshed) before another user can complete this course.
Technical Requirements
Internet access is required to complete this course.
Software Requirements
• Download and install the Postman application.
• In the ERP, generate an API Key in the API Key Maintenance program.
Note A valid API Key must be specified in any call against the Epicor REST API v.2.
This topic describes the Functions roles that will be used during this course.
Complete the steps below to assign a user to the Functions Administrator and Functions Power Developer
Security Groups:
1. Open User Account Security Maintenance and bring up the record for epicor.
3. From the Available column, select the Functions Administrator and Functions Power Developer groups,
and click the Right Arrow.
The groups move to the Authorized column.
Now let's see what you can do with Functions under these two roles:
• Functions Power Developer
Functions Power Developers assume all the capabilities available to Function Developers. Additionally, they
can perform the following operations with Epicor Functions:
• Enabling the Custom Code Widgets and Custom Code Functions options in library settings.
• Allowing access to database from Function code (DB Access from Code: none, read only, or read-write).
• Functions Administrator
Note By default, Security Managers and Global Security Managers are treated as Functions
Administrators even if they are not explicitly added to the Functions Administrator security group.
In Multi-Tenant environments, some functionality - for example, importing and installing libraries, is
available to Functions Administrators only if they are Global Security Managers.
As a Functions Administrator you cannot create new libraries and Functions. You can perform the following
operations (explained in the Introduction to Epicor Functions Course) with existing ones:
• Importing libraries - for example, from a Pilot environment.
• Exporting libraries (creating library backups).
• Deleting libraries, even if the library is in the Read-Only (RO) mode.
• Managing Company mapping (defining in what companies a library is enabled).
• Enabling and disabling libraries, even in the RO mode.
• Changing ownership and shared with group of unpublished (not promoted to Production) libraries, including
the ones in RO mode, in any Company.
• Promoting/demoting libraries to/from production.
• Enabling and disabling Functions, including the ones in RO mode.
This course will focus on two more operations available to Functions Administrators:
• Adding a Function library to a solution, and
• Installing Function libraries.
Note
A library/Function displays in Read-Only (RO) mode if:
• The current user is not the owner of the library, or is not a member of the Security Group the library
is shared with.
• The current Company is not the one the library has been created in.
• The library is published (promoted to Production).
In this section, walk through two examples of Functions that contain custom code.
You typically use custom code when you need to add logic that cannot be implemented using the available
widgets. Remember that only Functions Power Developers can add custom code to Functions.
• obtain the time zone information for this Zip Code from a third-party service via an open API
• return the offset to UTC in seconds.
This Function will handle some sensitive data like an API Key, therefore you will set this Function to be used
internally meaning that it will not be available for calls via REST. This "utility" Function will interact only with
another Function.
In this step, add a library that will contain utility Functions for internal use.
2. From the main Tool bar, click the Down Arrow next to the New icon and select Add Library.
3. For the Library ID, enter xxxUtils where xxx are your initials.
a. Click Add.
6. Navigate to the Security sheet and add Epicor Education to the list of Authorized Companies.
This will be enough for the purpose of this workshop. However, here you add all the companies your Function
library will be used in.
In this step, register an application with the ZipCodeAPI service and obtain an API Key.
Important ZipCodeAPI.com provides an easy way to calculate distances, radius, and locations for US zip
codes. It also provides time zone information for specific zip codes. The ZipCodeAPI is freely available but
has call frequency restriction. It also requires to register your application and get an API Key for it. The
service uses this API Key to identify the caller. The service is free as long as you do not make more than 10
API calls per hour. You should not exceed this number during this course. For more information on the
ZipCodeAPI service availability and commercial plans, visit https://www.zipcodeapi.com/Plans
In this workshop, the following API Key created for the MyEpicor application is used:
dh7fWRwinSOI64142frLrOhqFSkARhciwAIN8KJ61zQ9MjkyDP4Ap9CnCLmUrutW. You can use it in your
code, however, we recommend you register your own app and get another API Key to guarantee you do not
exceed the allowed number of 10 calls per hour. To do this:
2. Enter the Application Name for example, EpicorERP, Contact Name, Contact E-mail, and click Register
Your Application.
Important You must provide a valid E-mail address or you will not receive the activation link that is
required before you can use your API key.
3. Copy the Application Key that displays at the next registration step.
4. Activate the Key by following the link emailed by the service to the address you specified during registration.
Create Function
In this step, create a code-based Function that makes a REST call to the ZipCodeAPI web service.
1. From the main Tool bar, click the Down Arrow next to the New icon and select Add Custom Code
Function.
4. Navigate to the Function > Signature sheet and add the following Function parameters:
Request Parameters
Name Type
zipCode System.String
Response Parameters
Name Type
offset System.Int64
offset = long.MaxValue;
This Function calls the ZipCodeAPI to request information for the zip code that has been passed into it as a
request parameter and returns the time zone info (offset to UTC) that it extracts from the call response.
Note If you use your own API Key, make sure you substitute it in the request URL above.
Tip If the web resources you query use Self-Signed Certificates (SSC), you can handle them in two
ways:
• add the certificate to the Trusted Root Certification Authorities and address the resource by
its certificate name, or
• add this line to the REST client code in Function Editor:
client.RemoteCertificateValidationCallback = (sender, certificate, ch
ain, sslPolicyErrors) => true;
Note that this option turns off the validation of the resource Self-Signed Certificate, which can be
a security risk.
In this step, create a new library for the Function that obtains a zip code from the Customer table and returns
the customer zip code or an error message in case an error occurs.
1. In Epicor Functions Maintenance, from the main Tool bar, click the Down Arrow next to the New icon
and select Add Library.
2. For the Library ID, enter xxxCustLib where xxx are your initials.
4. Navigate to the References > Services sheet and add the Customer service:
• ERP:BO:Customer
5. Navigate to the Security sheet and add Epicor Education (EPIC06) to the list of Authorized Companies.
This will be enough for the purpose of this workshop. However, here you add all the companies your Function
library will be used in.
In this step, create a Widget Function that contains an Execute Custom Code widget.
You will work on this Function in two phases:
Phase 1 - Here you create a simple Widget Function that invokes the Customer Business Object (BO) and obtains
the value of the Zip Code field. It then performs a check on whether the Customer Number (CustNum) that has
been passed as the method's input parameter is correct. If the CustNum is valid, it returns the zip code value, if
not - displays an error message.
Phase 2 - During this phase, the Function will be modified and expanded. You will add logic for calling the
previously created Custom Code Function. It will use the response of the ZipCode-to-uts-offset Function in
calculating the local time of the customer. The local time will be displayed in the customized Customer
Maintenance menu.
In the scope of Phase 1, complete the steps below:
1. From the Tool bar, click the Down Arrow next to the New icon and select Add Widget Function with
Code.
3. Navigate to the Function > Signature sheet and add the following Function parameters:
Request Parameters
Name Type
custNum System.Int32
Response Parameters
Name Type
response System.String
Name Type
custTS CustomerTableset
zipCode String
Tip To define data type for the custTS parameter, from the Type drop-down, select Choose type...
On the Select type window, navigate to the Services sheet, expand the ERP:BO:Customer node,
and select Erp.Tablesets.CustomerTableset. Click OK.
To add a complex variable of Tableset type, you must have at least one service or assembly added to
the library as a reference. You add a service if you plan to invoke its method(s) in the Function workflow,
otherwise an assembly reference will suffice.
3. From the Callers pane, drag the Execute Custom Code widget and drop it onto design canvas and connect
the Start widget to it.
Configure the newly added widget:
d. Click OK.
4. From the Flow Chart pane, select the Condition widget and drag it to the canvas. Connect the previous
widget to it.
Configure the condition:
d. Click the first specified link and select the zipCode variable.
e. Keep the default is equal to segment and click the second specified link.
The Specify C# expression window displays.
g. Click OK.
5. Now add a Set Argument/Variable widget to the workflow and connect the True end of the condition
widget to it.
Configure the widget:
e. Click OK.
6. Finally, add another Set Argument/Variable widget to the workflow and connect the False end of the
condition widget to it.
Configure the widget:
e. Click OK.
Test Function
1. In Epicor Functions Maintenance, open the xxxCustLib library and go to Actions > Promote Library
to Production to publish it.
3. Open Postman and create a new POST request with the following URL:
https://[EpicorServer]/[ERPInstance]/api/v2/efx/EPIC06/xxxCustLib/LocalDate
Time
where EpicorServer is the server that hosts your ERP app server and ERPInstance is the name of your app
server.
KEY VALUE
x-api-key [API Key Value]
Content-Type application/json
Note You generate API Keys in the API Key Maintenance program. Please review the Introduction
to Epicor Functions course for details using API Keys in calls against the Epicor ERP REST API.
6. Open the Body tab and select the raw representation option.
9. Now change the CustNum parameter value to 999 and send the request again.
Besides BPM and web clients, Epicor Functions can be called from another Function or C# code of a UI
customization.
If you need to invoke a Function from another Function's workflow, you have to add the library that hosts the
Function you want to invoke to the current library as a reference. For example, in the first workshop of this
section, you will call the ZipCode-to-utc-offset "utility" Function from the LocalDateTime Function via the
Invoke Function widget action. To be able to this, you will add the Utils library to the list of library references
of the current xxxCustLib library.
Note The current library cannot be selected as a library reference. You cannot call a Function from another
Function within the same library.
Logic The system also does not allow adding libraries that can contain a direct or nested circular reference
to the current library. For example, Lib 2 references Lib 1, and Lib 3 references Lib 2. Adding Lib 3 as a
reference to Lib 1 (Lib 1 > Lib 3 > Lib 2 > Lib1) would cause an error.
The Epicor REST API C# Client provides a simple way of calling Epicor Functions via REST from a WinForms
client customization. This process can be broken into four parts: creating a C# client, specifying call parameters,
executing a call, and handling the response. You will go through these steps in the second workshop of this
section.
In this workshop, complete the steps for Phase 2 of the LocalDateTime Function development.
As a result, the modified LocalDateTime Function will:
• call the GetById method of the Customer BO
• obtain customer Zip Code
• call the ZipCode-to-utc-offset internal Function using the obtained Zip Code as a request parameter
• calculate the local date and time of the customer based on the current system time and the offset to UTC
value returned from the ZipCode-to-utc-offset Function
• return the customer's local date and time.
In this step, add reference to the xxxUtils library and update parameters of the LocalDateTime Function.
1. Open the xxxCustLib library and demote it from production (Actions > Demote Library form Production).
5. Open the LocalDateTime Function and navigate to the Function > Signature sheet.
6. Click Edit.
8. Add the localDateTimeString response parameter of the System.String type and click Complete.
Important In the next step you will replace the response parameter with the locaDateTimeString
parameter in the Function workflow. Do not save the Function now, otherwise you will get compilation
errors, and move on to the next step.
In this step, modify the workflow to add a Function call and calculation based on the response returned by the
ZipCode-to-uts-offset Function.
2. Navigate to the Properties > Variables sheet and click the New icon.
A new line is added to the list of existing variables.
Name Type
timeZoneOffset Long
4. Select the Set Argument/Variable widget that is connected to the True end of the condition.
Re-configure the widget:
a. Click the first link and replace the response parameter (argument) with the localDateTimeString
parameter.
b. Click the second link and change the expression to read like this:
"Verify CustNum/Zip"
c. Click OK.
5. Disconnect the second Set Argument/Variable widget from the False end of the condition and reconfigure
it as follows:
a. Click the first link and replace the response parameter (argument) with the localDateTimeString
parameter.
b. Click the second link and change the expression to read like this:
System.TimeZoneInfo
.ConvertTimeFromUtc(
DateTime.UtcNow,
System.TimeZoneInfo.CreateCustomTimeZone("CDT", TimeSpan.FromSeconds(ti
c. Click OK.
6. Now drag an Invoke Function widget from the Callers pane onto the canvas. Connect the False end of
the existing condition to the new Function widget.
If the BO Method call succeeds, this will be the next step in the workflow. Configure the widget:
g. In the Setup Function Parameters window, map the parameters of the ZipCode-to-utc-offset Function
to the variables of the LocalDateTime Function:
h. Click OK.
7. Finally, add another Condition widget to the workflow. Connect the Invoke Function widget to the new
Condition.
As before with the BO Method call, this condition checks if there's been an error returned from the
ZipCode-to-utc-offset Function and depending on the result of evaluation, returns either an error message
or the calculated local time of the customer.
Configure this condition as follows:
d. Click the first specified link and select the timeZoneOffset variable.
e. Keep the default is equal to segment and click the second specified link.
The Specify C# expression window displays.
g. Click OK.
h. Now connect the True end of the widget to the Set Argument/Variable that is connected to the True
end of the first Condition.
i. Connect the False end of the widget to the disconnected Set Argument/Variable widget you configured
in Step 5.
In this workshop, customize the Customer maintenance program to display local customer time.
During this workshop, you will:
• add two new controls to the Customer Maintenance program UI - a button and a label
• add code to call the LocalDateTime Function to the button click event
• create a menu for the customized program
• call the LocalDateTime Function for an existing customer from the customized program.
In this step, add two new controls to the Customer Maintenance program user interface (UI).
a. When running the application with Modern Home Page interface, you can do this by expanding the
Application Bar at the bottom of the home page and selecting the Wrench icon. Alternately, from the
application Home Page, go to the Settings page, select General Options, and then select Developer
Mode.
b. If you run the application using Kinetic Home Page interface, you can expand the Overflow menu in
the top right corner of the home page window and select Developer Mode.
6. Select EpiButton, then click on an empty space on the Customer Maintenance form where you what to
place it.
The Select Layer Type window displays.
9. Type in a name for your customization layer - XXXCustomerLocalTime where XXX are your initials, and
click Save.
In the Customization Comment window that pops up, click OK.
11. Change the value of the Misc > Text property to Get Local Time.
Then save your changes.
12. From the ToolBox, select epiLabel and click on a space near the new button.
The epiLabelC1 label is added to the UI.
13. Remove the text from the Misc > Text property.
Then save your changes.
Do not close the Customization Tools Dialog window and move on to the next step.
In this step, add a click event to the newly added button and add code for the LocalDateTime Function call.
This assembly is required by the Epicor REST Client Builder that you will use to set up your Function call.
4. Click OK.
The epiButtonC1_Click event displays in the pane on the right and the Control Event Code displays the
generated code.
10. Now click the Update Selected Event Code button in the lower part of the window.
Note that the generated button click event code has been added on the Script Editor sheet.
11. In the Script Editor, add the following items to the list of usings:
using Ice.Common;
using Ice.BO;
using Ice.Lib.RestClient;
13. Replace the // ** Place Event Handling Code Here ** comment inside the epiButtonC1_Click event
with the below code:
var restClient = new RestClientBuilder()
.SetDefaultApiKey(ApiKey)
.UseSession(this.oTrans.CoreSession)
.Build();
using (restClient)
{
try
{
var localDateTimeContent = new RestContent(
new { custNum = (int)this.Customer_Row.CurrentDataRow["Cus
tNum"] });
var localDateTimeResponse = restClient.Function.Post(
"xxxCustLib",
"LocalDateTime",
localDateTimeContent,
published: false);
var localDateTimeResult = localDateTimeResponse.GetAnonymousRe
sult(
new { localDateTimeString = (string)null });
this.epiLabelC1.Text = localDateTimeResult.localDateTimeString
;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Review the Full Script Code on page 27 sample to make sure you haven't missed any code.
14. Save your customization and close the Customization Tools Dialog.
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;
using Ice.BO;
using Ice.UI;
using Ice.Lib;
using Ice.Adapters;
using Ice.Lib.Customization;
using Ice.Lib.ExtendedProps;
using Ice.Lib.Framework;
using Ice.Lib.Searches;
using Ice.UI.FormFunctions;
using Ice.Common;
using Ice.BO;
using Ice.Lib.RestClient;
}
}
In this step, create a new menu item for the customized Customer Maintenance program.
2. In the Tree View, drill down to Main Menu > System Management > Business Process Management.
3. While the Business Process Management node is selected, from the Tool bar, click the Down Arrow
next to the New icon and select New Menu.
The Detail sheet activates.
4. For a Menu ID, enter UDXXX where XXX are your initials.
5. Enter a Name - for example, XXX Customer - Local Time (US) where XXX are your initials.
6. Set the Order Sequence to something like 300 to make it display at the end of the list.
7. Click the Program button and, from the Client folder, select the Erp.UI.CustomerEntry.dll assembly.
1. From the Epicor ERP Home Page, navigate to System Management > Business Process Management
and launch the XXX Customer - Local Time (US) program.
Functions Power Developers can use the DB Access from Code library setting to set up access to database from
Functions' custom code.
Important This functionality is reserved for advanced customization scenarios where you can't use standard
service methods and have to resort to direct access to database instead. We also recommend that if you
use a direct database update, you do it for User-Defined (UD) Tables and Fields only.
Important Only members of the Functions Power Developer security group can edit this field. This setting
is activated when the Custom Code Widgets or Custom Code Functions option is selected.
1. On the library's Summary sheet in Epicor Function Maintenance, set the DB Access from Code property
to Read Only.
3. In the Starting At field of the DB Table Search window, type in ud01 and press Search.
You can now read data directly from the ICE.UD01 table using custom code - for example:
var udRow = this.Db.UD01.FirstOrDefault(row =>; row.Key1 == "FuncTest");
if (udRow != null)
{
// The row is found. Access to udRow fields here.
}
1. On the library's Summary sheet in Epicor Function Maintenance, set the DB Access from Code property
to Read Write.
2. On the References > Tables, note that there is now the Updatable check box next to the UD01 table.
Select this check box.
You can now directly update the ICE.UD01 table using custom code - for example:
var udRow = this.Db.UD01.FirstOrDefault(row =>; row.Key1 == "FuncTest");
if (udRow != null)
{
udRow.Character01 = "Function says hello";
}
this.Db.SaveChanges();
Or, you can add a row to the UD01 table like this:
var udRow = new Ice.Tables.UD01();
udRow.Key1 = "AddKey1";
udRow.Key2 = "AddKey2";
udRow.Key3 = "AddKey3";
udRow.Key4 = "AddKey4";
udRow.Company = this.CompanyID;
udRow.Character01 = "The row was added from function";
this.Db.AddObject(udRow);
this.Db.SaveChanges();
This section explains how you can add a Function library to a solution and install it. It also provides a Function
scheduling example.
Important Only Security Managers (on premises installations and Cloud ERP) and Global Security Managers
(multi-tenant environments) can access Solution Workbench where they can build and install solutions with
Epicor Function library elements. Additionally, make sure the user account has the following options enabled:
• Can Create Solutions - for creating new solutions
• Can Install Solutions - for installing solutions
In Solution Workbench, you can add only one library to a solution. When you install a library, it is automatically
published (promoted to production). Installed libraries cannot be demoted from production.
By default, Solution Workbench installs the library to the current Company in upgrade mode trying to overwrite
the previously installed (if at all) version of this library. The upgrade of a library does not affect its company
mapping. However, if the existing library does not have a mapping to the current Company, such mapping is
added during the upgrade.
The Function scheduling functionality can be used for automation of various one-time or recurring tasks - for
example, processing files from a folder, dropping files in a cloud storage, reading emails from a pop3 account,
etc.
3. In the Solution field, enter XXXCustUSTime where XXX are your initials.
6. From the Available Elements list, select EfxLibrary and click Search.
The Advanced Element Search window displays.
Tip Alternately, on the Solution Element Search window, navigate to the User Defined sheet.
Click Get Adapters, select the LibrarySearchAdapter and click Search to launch the standard library
search window.
7. Click Search again. If necessary, use the Starting At field to enter criteria that will narrow the search.
Important Disabled libraries and libraries that have previously been installed in the system as part of
a solution are not available for selection and do not display in search results. Only one library can be
added to a solution.
8. Select the xxxCustLib library from the Search Results and click OK.
The library is added to the Selected Items list.
11. Select the Prompt For CAB File Name and Location option.
14. Accept the default solution file name - XXXCustUSTime_Customer Solution_3.2.xxx.x, where xxx.x is
your current ERP version, select the destination folder, and click Save.
A .cab solution file is generated and saved to the specified location.
You can now use the .cab file you just created to distribute your solution to other ERP deployments.
3. Click the Solution File button and select the XXXCustUSTime_Customer Solution_3.2.xxx.x.cab file.
6. Now, on the Summary sheet of the Epicor Functions Maintenance program, click the Library button.
The Library Search window displays.
7. Press Search.
Note you have the xxxCustLib library in the results.
In case there already is a library with the same ID in your system, when you install the solution, you are prompted
to confirm the update of the existing library record. Click Yes to continue or No to abort the installation. If you
click Yes, the system then verifies the OriginalID and GlobalID of the library being installed and the existing
one match and performs the update, otherwise the installation fails.
Function libraries installed in Standard or Hidden mode are exposed to BPM, other library, or REST calls just like
the Functions created and designed through Epicor Functions Maintenance. However, you cannot demote these
libraries from production. Any modifications to installed libraries can be done in their source environment only.
In the target environment, Functions Administrators can change their company mapping and disable/enable a
library and/or its Functions.
In this workshop, create a Function and schedule its execution in the Schedule Epicor Function program.
During scheduled execution, Functions are called asynchronously and you will not be able to process the values
of the response parameters (if any). However, in this workshop, you will find out about different ways of handling
the results of Function execution.
Note A Function can only be executed when called from a Company authorized in its library.
In this step, create a Function that will manage run out parts in the system.
You will create a Function that will regularly check the on-hand quantity of run out parts and, if the stock is
depleted, set such parts as Inactive. This Function will not return any confirmation of the change if it happens.
Important In this example, you will run the Function only against manufactured parts in the system. Part
is a complex business object (BO) that has numerous links to other BOs and its own complicated logic. The
purpose of this workshop is to demonstrate Function scheduling. Therefore, the logic of this Function is
intentionally simplified and does not cover all possible use cases and workflow options.
The Function logic doesn't include reporting on the results of the Function execution. It can be handled in
different ways - for example, by sending a report via email to a specified recipient or by writing the results
to a UD table.
1. In Epicor Functions Maintenance, create a xxxPartUtils library where xxx are your initials.
Name Type
typeCode System.String
This parameter will be used to specify a part's Type - Manufactured (M), Purchased (P), etc.
Note In this example, you will run the Function against the manufactured parts only.
9. Click Complete.
11. Navigate to the Usings sheet and add the following using statement:
using Erp.Tablesets;
12. Open the Code sheet and insert the below code into the editor:
PartRow[] parts = null;
if (parts.Length == 0)
{
return;
}
parts
.Select(r => new PartRow { Company = r.Company, PartNum = r.Par
tNum, InActive = true }));
errors = bo.UpdateExt(
ref updateTs,
continueProcessingOnError: true,
rollbackParentOnChildError: false,
out errorsOccurred);
});
if (errorsOccurred)
{
errors.BOUpdError
.Where(r => r.ErrorType == "Error" || r.ErrorType == "Exception")
.Select(r => r.ErrorText);
}
*/
In this step, create a part that you will use to test the scheduled Function.
2. In the Tool bar, click the Down Arrow next to the New icon and select New Part.
The Part > Detail sheet activates.
3. For the Part ID, type in XXXSamplePart where XXX are your initials.
You've specified the minimum number of properties required for this example. By default, the newly created
part has zero quantity on hand.
Note The Inactive check box is enabled and is not selected. XXXSamplePart has an active status.
Create Schedule
In this step, create a schedule in System Agent Maintenance. You will use this schedule to define the interval
of the DeactivateRunOuParts Function execution.
Important In Multi-Tenant environments, only Global Security Managers can view and edit the System
Agent record details. In other environments, only Security Managers have these privileges.
2. In the Tool bar, click the Down Arrow next to the New icon and select New Schedule.
The Schedules > Detail sheet activates.
4. In the Next Run field, open the calendar and select Today.
This sets the Next Run to the current date and time.
You can now use this schedule in the Schedule Epicor Function program.
Schedule Function
The System Agent will create a task for running the Function every 5 minutes.
1. Launch System Monitor and navigate to the History Tasks > Task Detail sheet.
It lists all completed tasks including Function runs.
Note The DeactivateRunOutParts Function has been scheduled to run every 5 minutes. If you
launch System Monitor right after you schedule the Function, you may need to wait a little to get the
first result.
5. Note that the Inactive check box is selected and a green shape is lit up.
The part has been set to Inactive status.
Important Make sure you cancel the Run Epicor Function task after you complete the workshop. To do
this, in the System Monitor, navigate to the Scheduled Tasks sheet, select your task, and press Delete
on your keyboard.
2. In the Tool bar, click the Down Arrow next to the New icon and select New Access Scope.
The Detail sheet activates.
4. Enter a Description - for example, Access Scope for the CoolApp application.
5. In the Tool bar, click the Down Arrow next to the New icon and select New Function Library.
The Library Search window displays.
6. Click Search.
7. Select the xxxCustLib library from the results and click OK.
Note the xxxCustLib library now appears in the Tree View.
8. In the Tool bar, click the Down Arrow next to the New icon and select New Function.
The Function Search window displays.
Note The search is conducted within the xxxCustLib library. If you are adding more than one library
to a Scope, make sure you select the library in the Tree View to specify the context for the Function
search.
9. Click Search.
You can now assign this Access Scope to the CoolApp's Integration Account in the Epicor ERP.
Conclusion