imported>Aeric |
imported>Aeric |
(9 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| '''Designer > Logic > Functions'''
| | {{Deprecated|Functions have been deprecated, along with this object. Existing functions can be edited, but it is no longer possible to create them. Instead of writing functions, the recommended practice is to write methods in Java [[Classes]], in order to gain the benefits of an improved [[Development Experience]]. }} |
|
| |
|
| {{:Function}} | | {{Deprecated_page|8.0|80}} |
| | |
| ==Writing Functions==
| |
| Functions work exactly like methods in Java code, and are written as if coding a method body in a Java class. You can consider functions as your own personal library of Java code.
| |
| | |
| Functions are written as if you are writing the body of a method. The platform injects the code you write into a Java [[Classes|class]], adds a method signature, compiles it, and stores the bytecode.
| |
| | |
| The following Java API classes are implicitly imported into functions:
| |
| | |
| :* [[Support_Classes_and_Objects#Result_Class|Result]]
| |
| :* [[Support_Classes_and_Objects#Parameters_Class|Parameters]]
| |
| :* [[Support_Classes_and_Objects#ParametersIterator_Class|ParametersIterator]]
| |
| :* [[Support_Classes_and_Objects#HttpConnection_Class|HttpConnection]]
| |
| :* [[Support_Classes_and_Objects#functionParams Object|functionParams Object]]
| |
| | |
| ==Accessing Parameters==
| |
| | |
| The [[functionParams Object|Java API <tt>functionParams</tt>]] object contains key-value pairs for the parameters passed to the current function:
| |
| :* When making a <tt>[[exec]]</tt> call, it is possible to specify a [[Parameters Class|<tt>Parameters</tt>]] object as an argument
| |
| | |
| Within a called function, access to the parameters is through the <tt>functionParams</tt> object. This example gets a parameter named <tt>number</tt> that was passed to the current function:
| |
| | |
| <pre>
| |
| String accountNumber = functionParams.get("number");
| |
| </pre>
| |
| | |
| ==Restrictions==
| |
| | |
| The Java code in functions follows the same restrictions as in [[Classes|classes]]. A complete list of restrictions is available in the [[Governors]] section.
| |
| | |
| ==Code Samples==
| |
| | |
| See [[Function Code Samples]] for example code that can be modified and used to create
| |
| | |
| ==Calling a Function==
| |
| Functions are invoked via [[Utility Calls#exec|exec]], and take arguments passed in [[functionParams Object]]s.
| |
| | |
| Functions can be invoked from:
| |
| | |
| * [[Utility Calls#exec|<tt>exec</tt>]] calls when you [[Invoke a Java Method From a Data Policy]]
| |
| * [[Utility Calls#exec|<tt>exec</tt>]] call from Java [[Classes]]
| |
| * From JSP [[Pages]]:
| |
| ** Using <tt>[[Utility Calls#exec|exec]]</tt> calls from embedded Java code
| |
| | |
| | |
| === Calling a Function from a Data Policy ===
| |
| | |
| This example calls a function named <tt>calculate_estimated_profit</tt> which takes in account’s revenue and calculates the profit as 30% of the revenue.
| |
| | |
| <pre>
| |
| float revenue = params.getFloat("revenue", 0.0);
| |
| Parameters params = Functions.getParametersInstance();
| |
| params.add("revenue", revenue);
| |
| float profit = Functions.exec("calculate_estimated_profit", params);
| |
| </pre>
| |
| | |
| === Calling a Function from a JSP Page ===
| |
| This example calls a <tt>someFunction</tt> from Java code embedded in a JSP page.
| |
| | |
| <pre>
| |
| <%
| |
| String result = someFunction();
| |
| %>
| |
| </pre>
| |
| | |
| ===Calling a Function from a Class===
| |
| | |
| This example shows calling a function named <tt>add_task</tt> from a class.
| |
| | |
| :<syntaxhighlight lang="java" enclose="div">
| |
| import com.platform.api.*;
| |
| | |
| | |
| import java.util.*;
| |
| | |
| public class ExecAddTask implements Controller
| |
| {
| |
| public ControllerResponse execute(HashMap params) throws Exception
| |
| {
| |
| String action = (String)params.get("action");
| |
| if(action == null || action.equals(""))
| |
| {
| |
| return null;
| |
| }
| |
| else
| |
| {
| |
| return addTasks(params);
| |
| }
| |
| }
| |
| private ControllerResponse addTasks(HashMap params) throws Exception
| |
| {
| |
| ControllerResponse cr = new ControllerResponse();
| |
| Result result = null;
| |
| try
| |
| {
| |
| Parameters addOptions = Functions.getParametersInstance();
| |
| addOptions.add("object_id", "CASE");
| |
| String objectID = (String)params.get("objectID");
| |
| String recordID = (String)params.get("recordID");
| |
| if (objectID!= null && !objectID.equals("")
| |
| && recordID!= null && !recordID.equals(""))
| |
| {
| |
| addOptions.add("object_id", objectID);
| |
| addOptions.add("record_id", recordID);
| |
| }
| |
| Functions.exec("add_task", addOptions);
| |
| Functions.debug("Message:" + result.getMessage());
| |
| params.remove("action");
| |
| cr.setData(result);
| |
| cr.setTargetPage("ManageCases.jsp");
| |
| }
| |
| catch(Exception e)
| |
| {
| |
| cr.setTargetPage("ManageCases.jsp");
| |
| cr.setMessage(e.getMessage());
| |
| Functions.debug("Message:" + result.getMessage());
| |
| }
| |
| return cr;
| |
| }
| |
| }
| |
| </syntaxhighlight>
| |
| | |
| ==Manage Functions==
| |
| | |
| {{permissions|Customize Objects|Add, Edit or Delete a Function}}
| |
| | |
| === Add a Function ===
| |
| #Click '''Designer > Logic > Functions > New Function'''
| |
| #Complete the following required information
| |
| #;Title:Name of the Function
| |
| #;Function Name:Programmatic name of the Function; Only alphanumeric characters and underscore allowed; In this example, enter: add_task
| |
| #;Description:Description of the function, how it works, circumstances for use
| |
| #;Function Button: Optionally, add a function from a list of predefined functions, defined in [[Java API]]
| |
| #Enter the code into the editing area, then click the [Save] button to save the code
| |
| | |
| === Edit a Function ===
| |
| # Click '''Designer > Logic > Functions'''
| |
| # Select the function to edit
| |
| #Edit the following fields:
| |
| #;Title:Name of the Function
| |
| #;Function Name:Programmatic name of the Function; Only alphanumeric characters and underscore allowed; In this example, enter: add_task
| |
| #;Description:Description of the function, how it works, circumstances for use
| |
| #;Function Button: Optionally, add a function from a list of predefined functions, defined in [[Java API]]
| |
| #Edit the code in the editing area, then click the [Save] button to save the code or click [Cancel] to stop the process
| |
| | |
| === Delete a Function ===
| |
| # Click '''Designer > Logic > Functions'''
| |
| # Click the name of the function to delete
| |
| # Click the [Delete] button or click [Cancel] to stop the process
| |
| | |
| == Editing Functions in Eclipse ==
| |
| Functions can also be added, edited, and deleted using the [[Eclipse Plug-In]].
| |
| | |
| | |
| <noinclude>[[Category:Develop| 10]]</noinclude>
| |