0% found this document useful (0 votes)
3K views

Advanced Epicor Functions

Uploaded by

Huyen Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

Advanced Epicor Functions

Uploaded by

Huyen Phan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

Epicor Kinetic - Classic User Interface

Advanced Epicor Functions


11.1
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 2021.
All rights reserved. Not for distribution or republication. Information in this document is subject to Epicor license
agreement(s).

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

Epicor Kinetic - Classic User Interface | 11.1 3


Contents Advanced Epicor Functions

Conclusion.............................................................................................................................42

4 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Epicor Functions

Advanced Epicor Functions

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.

Epicor Kinetic - Classic User Interface | 11.1 5


Before You Begin Advanced Epicor Functions

Before You Begin

Read this topic for information you should know in order to successfully complete this course.

Audience

Specific audiences will benefit from this course.


• Engineer
• System Administrator
• IT/Technical Staff

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.

6 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Before You Begin

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. Log in to the training environment using the credentials epicor/epicor.


If you are asked to log into your training environment with another User ID, for example, 'nancy' or 'bhoward',
on the initial logon, a message appears to inform you the password has expired. Perform the following steps
to set a new password:

1. To the Password Expired message, click Yes.

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.

4. In the Confirm new password field, re-enter the same password.

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.

Epicor Kinetic - Classic User Interface | 11.1 7


Before You Begin Advanced Epicor Functions

3. From the Main menu, select the company Epicor Education (EPIC06).

4. From the Main menu, select the Main site.

Kinetic Interface Specific Information


All the workshops in this course can be completed using the Classic layout. To ensure that the user interfaces
used in this course display in the Classic layout, use the steps below:

1. Navigate to Kinetic Application Maintenance.


Menu Path: System Setup > Security Maintenance > Kinetic Application Maintenance

2. From the Menu list, select the Epicor Education company.


The Company Epic Corporation pane displays.
Note If you need to work in a multi-company environment you will have to disable the Kinetic layout
for all the companies used in the course.

3. Inactivate the Enable Kinetic UI ON/OFF button.

4. Exit Kinetic Application Maintenance.

5. On the standard toolbar, select Options > Preferences.

6. In the window that displays, in the Form To Use field, select Classic.

7. Select OK to confirm.

8. Relaunch Epicor ERP.

Epicor Cloud ERP Specific Information


Note If you are an Epicor Cloud ERP customer, then note the following about your Epicor-hosted education
company. All logins referenced in the course (such as manager, or epicor) should be changed to be the
<site ID>-. For example, if your site ID is 98315, then wherever you are instructed to use the login manager,
instead use 98315-manager. The password is 'Train18!'.

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.

Required User Privileges


To be able to access some programs and complete the workshops of this course, make sure the epicor account
you are using has the following options selected:
• Security Manager
• Customize Privileges
• Can Create Solutions

8 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Before You Begin

• Can Install Solutions

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.

Epicor Kinetic - Classic User Interface | 11.1 9


Functions Security Group Setup Advanced Epicor Functions

Functions Security Group Setup

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.

2. Navigate to the Group sheet.

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.

4. Click Save and close the program.

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.

10 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Functions Security Group Setup

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).

Epicor Kinetic - Classic User Interface | 11.1 11


Creating Custom Code in Functions Advanced Epicor Functions

Creating Custom Code in Functions

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.

Workshop - Create Custom Code Function

In this workshop, create a Custom Code Function.


The Function you create during this workshop will:
• accept a customer Zip Code as an input parameter
Important The Function will work with US zip codes ONLY.

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

Create Library for Utility Functions

In this step, add a library that will contain utility Functions for internal use.

1. Launch Epicor Functions Maintenance.


Menu Path: System Management > Business Process Management > Epicor Functions Maintenance.

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.

4. Select the following options:


• Custom Code Functions - This option, available to Functions Power Developers Only, allows adding
Custom Code Functions to the library.
• For Internal Use Only - This will not allow calling this Function from external systems via REST.

5. Navigate to the References > Assemblies sheet.


Note In this example, we will use RestSharp, an open-source HTTP client library that makes it easy
to consume RESTful services, to make a REST call against an external API. As of the Epicor ERP version
10.2.700, this library is part of the Epicor application server source code.
We will use Newtonsoft JSON library for handling requests and responses in JSON format.

a. Click Add.

12 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Creating Custom Code in Functions

The Select Assembly window displays.


Note It may take some time for the system to download the full list of assemblies.

b. Select RestSharp.dll and click OK.

c. Click Add again.

d. Select Newtonsoft.Json.dll and click OK.

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.

7. Save the library.

Register Your App with ZipCodeAPI

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:

1. In your browser, go to https://www.zipcodeapi.com/Register.

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.

2. For the Function ID, enter ZipCode-to-utc-offset.

Epicor Kinetic - Classic User Interface | 11.1 13


Creating Custom Code in Functions Advanced Epicor Functions

3. For the Description, type in:


The function returns UTC offset in seconds for the passed zip code. Currently works for the US
zip codes only.
Note By default, this Function is marked as For Internal Use Only because this setting is activated
on the library level.

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

5. Save the Function.

Add Function Code

In this step, add code to the ZipCode-to-utc-offset Function.

1. On the ZipCode-to-utc-offset Function sheet, click Edit.


The Function Editor window displays.

2. Navigate to the Usings sheet.


It has two panes. The first one contains the default list of usings. The second is for user-defined usings.

3. Add the below usings into the second pane:


• using RestSharp;
• using Newtonsoft.Json.Linq;

4. Now open the Code sheet and add this code:


var client = new RestClient("https://www.zipcodeapi.com/rest/");
var request = new RestRequest("dh7fWRwinSOI64142frLrOhqFSkARhciwAIN8KJ61zQ9
MjkyDP4Ap9CnCLmUrutW/info.json/" + zipCode, Method.GET);

var response = client.Execute(request);


if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var json = JObject.Parse(response.Content);
var offsetString = json["timezone"]["utc_offset_sec"].Value<string>();

if (long.TryParse(offsetString, out offset))


{
return;
}
}

14 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Creating Custom Code in Functions

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.

5. Click OK to close the Function Editor.

6. Save the Function.

Workshop - Create Widget Function with Custom Code

In this workshop, create a Widget Function with Code.


Initially, the Function you create during this workshop will:
• make a call to the GetById method of the Customer BO
• return the customer Zip Code obtained from the Customer Tableset.
You will use custom code for more efficient handling of possible errors. For example, if you send a wrong request
parameter to the BO - a CustNum in this case, it will return an extensive error message. Later in this course, you
will call this Function from a customized program UI. If an error occurs, the Function will return an error message
to a UI control (epiLabel) that has a limited text capacity. Therefore, you will need to set a condition that will
evaluate the result of the custom code execution and handle possible errors.
In the workshops that follow, you will further modify this Function by adding a call to the Function you created
in the previous workshop and some extra calculation logic.

Create xxxCustLib Library

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.

Epicor Kinetic - Classic User Interface | 11.1 15


Creating Custom Code in Functions Advanced Epicor Functions

3. Select the following options:


• Custom Code Widgets - This option, available to Functions Power Developers Only, allows adding
Custom Code Widgets into the workflows of this library's Functions.

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.

6. Save the library.

Add Widget Function with Code

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.

2. Type in LocalDateTime for the Function ID.

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

4. Save the Function.

16 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Creating Custom Code in Functions

Design Function Workflow

In this step, design the workflow of the LocalDateTime Function.

1. Open the LocalDateTime Function and click Design.


The Function Designer displays.

2. Add the following Function-level variables:

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:

a. Select the widget you just added.


The Actions sheet displays in the Properties pane below.

b. In the action statement, click the code... link.


The Enter Custom Code window displays.

c. Paste the below code into the editor:


try
{
this.CallService<Erp.Contracts.CustomerSvcContract>(
bo =>
{
custTS = bo.GetByID(custNum);
zipCode = custTS.Customer.Single().Zip;
});
}
catch
{
zipCode = "";
}
This BO method call returns the Customer's zip code if the CustNum value is valid, otherwise it returns
a null.

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:

Epicor Kinetic - Classic User Interface | 11.1 17


Creating Custom Code in Functions Advanced Epicor Functions

a. Select the Condition widget.


The Condition sheet displays in the Properties pane below.

b. Click the New icon.

c. Select the following condition statement:


The specified argument/variable is equal to the specified expression.

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.

f. Enter the following expression:


""
that signifies an empty string.

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:

a. In the action statement, click the first specified link.


The Select an Argument/Variable window displays.

b. Select the response parameter (argument).

c. Click the second specified link.


The Specify C# expression window displays.

d. For the expression enter this:


"Wrong Customer Number"

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:

a. In the action statement, click the first specified link.


The Select an Argument/Variable window displays.

b. Select the response parameter (argument).

c. Click the second specified link.


The Specify C# expression window displays.

d. For the expression enter this:


"Customer Number OK, Zip Code:" + custTSCustomerRow.Zip

e. Click OK.

7. Save the workflow and close the Function Designer.

18 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Creating Custom Code in Functions

8. Save the Function and the library.

Test Function

In this step, run a quick Function test via REST.


Download and install the free Postman app here.
Tip Please review the Introduction to Epicor Functions course for details on using Postman.

1. In Epicor Functions Maintenance, open the xxxCustLib library and go to Actions > Promote Library
to Production to publish it.

2. Save the Function.

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.

4. On the Authorization tab, select Basic Auth for TYPE.


For user name/password, specify epicor/epicor.

5. Open the Headers tab and add the following items:

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.

7. Specify the request parameter in JSON format:


{
"CustNum" : "2"
}

8. Send the request.


The response body contains the following code:
{
"response": "Customer Number OK, Zip Code:53703"
}

9. Now change the CustNum parameter value to 999 and send the request again.

Epicor Kinetic - Classic User Interface | 11.1 19


Creating Custom Code in Functions Advanced Epicor Functions

The response body contains the following code:


{
"response": "Wrong Customer Number"
}

20 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Usage of Epicor Functions

Advanced Usage of Epicor Functions

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.

Workshop - Call Function from Another Function

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.

Modify Library Settings and Function Signature

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).

2. Navigate to the References > Libraries sheet and click Add.


The Library Search window displays.
Note By default, the system searches for enabled libraries set to production. Set the In Production
setting to display libraries with both production statuses.

3. Select the xxxUtils library and click OK.

Epicor Kinetic - Classic User Interface | 11.1 21


Advanced Usage of Epicor Functions Advanced Epicor Functions

4. Save the xxxCustLib library.

5. Open the LocalDateTime Function and navigate to the Function > Signature sheet.

6. Click Edit.

7. Delete the response output parameter.

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.

Invoke Function and Calculate Local Time

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.

1. Open the LocalDateTime Function and click Design.


The Function Designer displays.

2. Navigate to the Properties > Variables sheet and click the New icon.
A new line is added to the list of existing variables.

3. Add another Function-level variable:

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

22 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Usage of Epicor Functions

meZoneOffset), "custom zone", "America"))


.ToString()

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:

a. Select the Invoke Function widget.


The Actions sheet displays in the Properties pane below.

b. Click the library link.


The Select Library window displays.

c. Select the xxxUtils library and click OK.

d. Click the function link.


The Function Search window displays.

e. Select the ZipCode-to-utc-offset Function and click OK.

f. Click the not configured link.

g. In the Setup Function Parameters window, map the parameters of the ZipCode-to-utc-offset Function
to the variables of the LocalDateTime Function:

Name Type Direction Binding


zipCode string in var: zipCode
offset long out var: timeZoneOffset

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:

a. Select the Condition widget you just added.


The Condition sheet displays in the Properties pane below.

b. Click the New icon.

c. Select the following condition statement:


The specified argument/variable is equal to the specified expression.

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.

Epicor Kinetic - Classic User Interface | 11.1 23


Advanced Usage of Epicor Functions Advanced Epicor Functions

f. Enter the following expression:


long.MaxValue

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.

8. Save the workflow and close the Function Designer.

9. Save the Function.

Workshop - Call Function from Client Customization

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.

Add New UI Controls to Customer Maintenance

In this step, add two new controls to the Customer Maintenance program user interface (UI).

1. Turn on Developer Mode in the Epicor ERP:

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.

2. Launch the Customer maintenance program.


The Select Customization window displays first.

3. Select the Base Only option and click OK.


The Customer Maintenance program opens.

4. In the Main Menu, go to Tools > Customization.


The Customization Tools Dialog window displays.

5. Now go to Tools > ToolBox


The ToolBox window displays.

24 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Usage of Epicor Functions

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.

7. Select Customization and click OK.


The new epiButtonC1 appears on the form.

8. In the Customization Tools Dialog window, click Save.


The Customization Save Dialog 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.

10. Now, on the form, select the newly added button.


The Customization Tools Dialog (CustomerLocalTime) window displays the properties of the control.

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.

Add and Configure REST Client

In this step, add a click event to the newly added button and add code for the LocalDateTime Function call.

1. In the Customization Tools Dialog, go to Tools > Assembly Reference Manager.


The Custom Assembly Reference Manager window displays.

2. Click Add Custom Reference.

3. From the Client folder, select the Epicor.Ice.Lib.RestClient.dll assembly.


Note Select All files (*.*) from the file name filter to be able to select this assembly.

This assembly is required by the Epicor REST Client Builder that you will use to set up your Function call.

4. Click OK.

5. Navigate to the Wizards > Event Wizard sheet.

6. From the Control Type Filter drop-down, select All.

7. From the Custom Control drop-down, select epiButtonC1.

8. From the Available Control Events drop-down, select Click.

9. Click the Right Arrow.

Epicor Kinetic - Classic User Interface | 11.1 25


Advanced Usage of Epicor Functions Advanced Epicor Functions

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;

12. In this example, define your API key as constant:


private const string ApiKey = "Yla2KAAsJlDtKvsVzzECT5BwKbduQ7beq0SnDvFeNwcN
h";
Note Do not forget to replace the API Key with the actual value.

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.

15. Turn off Developer Mode.

26 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Usage of Epicor Functions

Full Script Code


The final script in the Script Editor should look like this:
// **************************************************
// Custom code for CustomizationMaintForm
// Created: 4/10/2020 4:11:20 PM
// **************************************************

extern alias Ice_Adapters_GenXData;


extern alias Ice_Adapters_UserFile;

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;

public class Script


{
// ** Wizard Insert Location - Do Not Remove 'Begin/End Wizard Added Module
Level Variables' Comments! **
// Begin Wizard Added Module Level Variables **

// End Wizard Added Module Level Variables **

// Add Custom Module Level Variables Here **

public void InitializeCustomCode()


{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Va
riable Initialization' lines **
// Begin Wizard Added Variable Initialization

// End Wizard Added Variable Initialization

// Begin Wizard Added Custom Method Calls

this.epiButtonC1.Click += new System.EventHandler(this.epiButtonC1_Clic


k);
// End Wizard Added Custom Method Calls
}

public void DestroyCustomCode()


{
// ** Wizard Insert Location - Do not delete 'Begin/End Wizard Added Ob
ject Disposal' lines **
// Begin Wizard Added Object Disposal

this.epiButtonC1.Click -= new System.EventHandler(this.epiButtonC1_Clic


k);

Epicor Kinetic - Classic User Interface | 11.1 27


Advanced Usage of Epicor Functions Advanced Epicor Functions

// End Wizard Added Object Disposal

// Begin Custom Code Disposal

// End Custom Code Disposal


}

private const string ApiKey = "Yla2KAAsJlDtKvsVzzECT5BwKbduQ7beq0SnDvFeNwcN


h";

private void epiButtonC1_Click(object sender, System.EventArgs args)


{
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["CustNum"] });
var localDateTimeResponse = restClient.Function.Post(
"xxxCustLib",
"LocalDateTime",
localDateTimeContent,
published: false);
var localDateTimeResult = localDateTimeResponse.GetAnonymousResult(
new { localDateTimeString = (string)null });
this.epiLabelC1.Text = localDateTimeResult.localDateTimeString;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}

}
}

Add Menu for Customized Program

In this step, create a new menu item for the customized Customer Maintenance program.

1. Launch Menu Maintenance.


Menu Path: System Setup > Security Maintenance > Menu Maintenance.

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.

28 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Usage of Epicor Functions

7. Click the Program button and, from the Client folder, select the Erp.UI.CustomerEntry.dll assembly.

8. From the Customization drop-down list, select your customization - XXXCustomerLocalTime.

9. Save the new menu and restart the ERP application.

Invoke Function from Customization

In this step, call the Function from the customized form.


Remember that the newly added logic works only for customers located in the US.

1. From the Epicor ERP Home Page, navigate to System Management > Business Process Management
and launch the XXX Customer - Local Time (US) program.

2. For the Customer ID, type in addison and click Tab.


The record for Addison is brought up.

3. Now click the Get Local Time button.


The label displays the current date and local time for Addison.

Epicor Kinetic - Classic User Interface | 11.1 29


Database Access from Custom Code of Epicor Functions Advanced Epicor Functions

Database Access from Custom Code of Epicor Functions

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.

The DB Access from Code setting has three options:


• None - Select this option if you do not wish that the expressions and custom code actions from the function
workflow had access to the Epicor database.
• Read Only - Select this option if you want to enable a read-only access from expressions and custom code
workflow actions of your Function to the database tables specified in the library Table References.
• Read Write - Select this option if you want to be able to update the database tables that are specified in the
library Table References from expressions and custom code workflow actions of your Function.

Setting Up Read-Only Access from Code


For example, perform the following steps to set up a read-only access to the ICE.UD01 table from the custom
code of the ZipCode-to-utc-offset Function in the xxxUtils library you created in the first workshop:

1. On the library's Summary sheet in Epicor Function Maintenance, set the DB Access from Code property
to Read Only.

2. Navigate to the References > Tables sheet and click Add.

3. In the Starting At field of the DB Table Search window, type in ud01 and press Search.

4. Select the UD01 table and click OK.

5. Save the library.

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.
}

Setting Up Read-Write Access from Code


Perform the following steps to enable updating of the ICE.UD01 table from the same library (xxxUtils):

1. On the library's Summary sheet in Epicor Function Maintenance, set the DB Access from Code property
to Read Write.

30 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Database Access from Custom Code of Epicor Functions

2. On the References > Tables, note that there is now the Updatable check box next to the UD01 table.
Select this check box.

3. Save the library.

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();

Epicor Kinetic - Classic User Interface | 11.1 31


Advanced Function Administration Advanced Epicor Functions

Advanced Function Administration

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.

Workshop - Add Library to Solution

In this workshop, add the xxxCustLib library to a new solution.

1. Open Solution Workbench.


Menu Path: System Management > Solution Management > Solution Workbench
Important This program is not available in Epicor Web Access.

2. Click the New icon in the Tool bar


The Detail sheet activates.

3. In the Solution field, enter XXXCustUSTime where XXX are your initials.

4. Select ALL for Solution Type and save the changes.

5. Click the Add to Solution button.


The Solution Element Search window displays.

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.

32 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Function Administration

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.

9. Click Add to Solution.


The library is added to the Detail > Solution sheet.

10. Select Actions > Build Solution.


The Build Solution window displays.

11. Select the Prompt For CAB File Name and Location option.

12. From the Library Type drop-down, select Editable.


This setting defines the build and install mode for all libraries in the solution. The available options are:
• (blank) - Keep this default value if you don't have any Function libraries in your solution.
• Editable - Use this type to allow making changes to the library after it's been installed in a target
environment. In Cloud ERP, this can be used to move complex solutions that contain Functions from
pilot to production environment.
• Standard - Use this type to make the installed library as read-only. After the installation, users will be
able to see Function settings and workflow but will not be able to edit them.
• Hidden - If you select this type, when the library gets installed, it will be available for calls from BPM
directives, other Functions using the Invoke Function action or custom code, or via REST API, but only
Security Managers and Global Security Managers will be able to view this library in Epicor Functions
Maintenance.
To ensure successful installation of multiple libraries within a solution, the system analyzes library dependencies
and sets the correct installation order during the solution build process. For example, if Library A references
Library B, the system will first install Library B and then Library A. Otherwise, Library A would fail to compile
because of missing references.

13. Press Build.


The Save CAB File window displays.

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.

15. Once the build process is complete, close the window.

You can now use the .cab file you just created to distribute your solution to other ERP deployments.

Epicor Kinetic - Classic User Interface | 11.1 33


Advanced Function Administration Advanced Epicor Functions

Workshop - Install Function Library

In this workshop, install the XXXCustUSTime solution into your system.


Typically, you wouldn't need to install a library into its original ERP environment - its's already there. For the
purpose of this workshop, complete the below prerequisites to simulate the process of installing a solution into
a different environment - for example, when you copy a library from a Pilot system into Production:
• Create a backup of the xxxCustLib library.
• Delete the xxxCustLib library from the system.

1. Clear the Solution Workbench form.

2. From the Main Menu, go to Actions > Install Solution.


The Install Solution window displays.

3. Click the Solution File button and select the XXXCustUSTime_Customer Solution_3.2.xxx.x.cab file.

4. Keep all default settings and click Install.


In the previous step, we built the solution with Editable Library Type. Therefore, all libraries in this solution
are deployed using the standard import logic.

5. Once the installation process is complete, close the window.

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.

8. Open the library.


Note that like any imported library, it is automatically promoted to production. Demote it from productions
to allow modifications.

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.

34 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Function Administration

Workshop - Schedule Function

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.

Create Function to Manage Run Out Parts with Depleted Stock

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.

2. Enable Custom Code Functions.

3. Add the following reference on the References > Services sheet:


• ERP:BO:Part

4. On the Security sheet, authorize the EPIC06 company.

5. Save the library.

6. Next, add a Custom Code Function.


For an ID, enter DeactivateRunOutParts.

7. Navigate to the Function > Signature sheet and click Edit.

8. Add the following request parameter:

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.

Epicor Kinetic - Classic User Interface | 11.1 35


Advanced Function Administration Advanced Epicor Functions

9. Click Complete.

10. In the Summary section, click Edit.


The Function Editor launches.

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;

// Select Parts with specific flags


this.CallService<Erp.Contracts.PartSvcContract>(
bo =>
{
parts = bo.GetRows(
whereClausePart: "RunOut=TRUE AND InActive=FALSE AND TypeCode='
" + typeCode + "'",
whereClausePartAttch: "1=0",
whereClausePartCOO: "1=0",
whereClausePartDim: "1=0",
whereClausePartLangDesc: "1=0",
whereClausePartPlant: "1=0",
whereClausePartRestriction: "1=0",
whereClausePartRestrictSubst: "1=0",
whereClausePartRev: "1=0",
whereClausePartRevAttch: "1=0",
whereClausePartAudit: "1=0",
whereClausePartCOPart: "1=0",
whereClausePartRevInspPlan: "1=0",
whereClausePartRevInspPlanAttch: "1=0",
whereClausePartRevInspVend: "1=0",
whereClausePartSubs: "1=0",
whereClausePartPC: "1=0",
whereClausePartWhse: "1=0",
whereClausePartBinInfo: "1=0",
whereClausePartUOM: "1=0",
whereClauseEntityGLC: "1=0",
whereClauseTaxExempt: "1=0",
pageSize: 100,
absolutePage: 0,
out _)
.Part
.Where(r => r.EnableInActive && !r.HasOnHandQty)
.ToArray();
});

if (parts.Length == 0)
{
return;
}

bool errorsOccurred = false;


BOUpdErrorTableset errors;

// Set parts as inactive


this.CallService<Erp.Contracts.PartSvcContract>(
bo =>
{
var updateTs = new UpdExtPartTableset();
updateTs.Part.AddRange(

36 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Function Administration

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);
});

/* Consider handling and reporting errors occured during update

if (errorsOccurred)
{
errors.BOUpdError
.Where(r => r.ErrorType == "Error" || r.ErrorType == "Exception")
.Select(r => r.ErrorText);
}
*/

13. Press OK.


The Function Editor closes.

14. Save the DeactivateRunOutParts Function.

15. Promote the xxxPartUtils library to production.

Add New Part for Testing Function

In this step, create a part that you will use to test the scheduled Function.

1. Launch the Part Maintenance program.

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.

4. For Description, enter Used for testing a scheduled Function.

5. In the Type drop-down, select Manufactured.

6. Select the Run Out option.

7. Save the new part and close the program.

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.

Epicor Kinetic - Classic User Interface | 11.1 37


Advanced Function Administration Advanced Epicor Functions

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.

1. Launch System Agent Maintenance.


Menu Path: System Setup > System Maintenance > System Agent Maintenance.

2. In the Tool bar, click the Down Arrow next to the New icon and select New Schedule.
The Schedules > Detail sheet activates.

3. For Description, enter Every 5 Minutes.

4. In the Next Run field, open the calendar and select Today.
This sets the Next Run to the current date and time.

5. From the Schedule Type drop-down, select Interval.


Three new fields appear below - Hours, Minutes, and Seconds.

6. Set the value of the Minutes field to 5.

7. Save the schedule and close the program.

You can now use this schedule in the Schedule Epicor Function program.

Schedule Function

In this step, schedule the execution of the Function.

1. Launch the Schedule Epicor Function program.


Menu Path: System Management > Business Process Management.

2. Click the Library ID button and select the xxxPartUtils library.

3. From the Function ID drop-down, select the DeactivateRunOutParts Function.

4. For the typeCode parameter, enter M.


M stands for manufactured parts.

5. From the Schedule drop-down, select Every 5 Minutes.

6. Select the Recurring check box.

7. In the Tool bar, click Submit.

The System Agent will create a task for running the Function every 5 minutes.

38 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Function Administration

Test Function Execution

In this step, check how the Function you scheduled works.

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.

2. Verify the Run Epicor Function task has a COMPLETE status.


This means that the Function has been executed and you can check the result.

3. Launch Part again.

4. In the Part field, type in XXXSamplePart and press Tab.


The part details display.

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.

Epicor Kinetic - Classic User Interface | 11.1 39


Advanced Function Security Advanced Epicor Functions

Advanced Function Security

Functions can be added to an Access Scope.


An Access Scope groups one or more ERP Services, specific Service Methods, Function Libraries, Functions, and/or
Business Activity Queries (BAQs) under an Access Scope ID.
When a Security Manager or Global Security Manager links a user to an active Access Scope, only those services,
service methods, Function libraries, Functions, or BAQs explicitly allowed via the Access Scope can be executed
by that user. All calls to services, Functions, or BAQs not specified in the Access Scope are denied.
While Access Scopes can be assigned to individual users if needed, they are expected to be primarily used for
Integration Accounts where an external application communicates with the Epicor ERP Services under a common
User ID.
If an Integration Account or, in other words, external application has an Access Scope assigned to it, it can only
call the Functions that are explicitly added to its Access Scope. Calls to Functions that are not included in the
Access Scope will be denied.

Workshop - Add Function to an Access Scope

In this workshop, add the xxxCustLib library to an Access Scope.


Imagine there is an external application, CoolApp, integrated with the Epicor ERP. It uses an Integration Account
to log into the ERP. You first create an Access Scope that will be assigned to this Integration Account. You then
define what services, service methods, BAQs, libraries, and Functions CoolApp will have access to.

1. Launch Access Scope Maintenance.


Menu Path: System Setup > Security Maintenance > Access Scope Maintenance.

2. In the Tool bar, click the Down Arrow next to the New icon and select New Access Scope.
The Detail sheet activates.

3. For the Access Scope ID, type in CoolApp.

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.

40 Epicor Kinetic - Classic User Interface | 11.1


Advanced Epicor Functions Advanced Function Security

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.

10. Select the LocalDateTime Function and click OK.


The LocalDateTime Function is added to the list of Functions in the Tree View.

11. Save the Access Scope.

You can now assign this Access Scope to the CoolApp's Integration Account in the Epicor ERP.

Epicor Kinetic - Classic User Interface | 11.1 41


Conclusion Advanced Epicor Functions

Conclusion

Congratulations! You have completed the Advanced Epicor Functions course.

42 Epicor Kinetic - Classic User Interface | 11.1


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