# Custom Function

A custom function in the 200 OK application allows users to define their own logic using the interface provided within the Apex environment. This empowers users to tailor the application to their specific needs, incorporating custom business logics,  and data processing operations seamlessly into their processes.\
\
Below is the sample class for creating your own Custom Function\
\
**Apex Class:**\
\
global class CustomDateTimeFormatter implements lwapic.IICCallableService {

&#x20;   global Object call(String action, Map\<String, Object> params) {

&#x20;       Object dataToReturn = new Map\<String, Object>();

&#x20;       if (action.equalsIgnoreCase('fx\_formatDateTime')) {

&#x20;           dataToReturn = formatDateTime(params);

&#x20;       }

&#x20;       return dataToReturn;

&#x20;   }\
&#x20;       private Object formatDateTime(Map\<String, Object> params) {

&#x20;       List\<Object> paramList = (List\<Object>) params.get('input');

&#x20;       String dateTimeString = String.valueOf(paramList.get(0));

&#x20;       Integer year   = Integer.valueOf(dateTimeString.substring(0, 4));

&#x20;       Integer month  = Integer.valueOf(dateTimeString.substring(5, 7));

&#x20;       Integer day    = Integer.valueOf(dateTimeString.substring(8, 10));

&#x20;       Integer hour   = Integer.valueOf(dateTimeString.substring(11, 13));

&#x20;       Integer minute = Integer.valueOf(dateTimeString.substring(14, 16));

&#x20;       Integer second = Integer.valueOf(dateTimeString.substring(17, 19));

&#x20;       Datetime formattedDateTime = Datetime.newInstanceGmt(year, month, day, hour, minute, second);       &#x20;

&#x20;       Map\<String, Object> resultMap = new Map\<String, Object>();

&#x20;       resultMap.put('result', formattedDateTime);

&#x20;       return resultMap;

&#x20;   }

}\
\
\&#xNAN;**\*Note :-** \
\
1\. When implementing a custom class using this interface, we must use a global access modifier. The     **lwapic.IICCallableService** interface includes a method named **call**, which accepts two inputs:  "string" and "map"(containing a string and an object).\
\
2\. In the CustomDateTimeFormatter class, we implement the **lwapic.IICCallableService** interface. \
\
3\. The **call** method checks the action parameter to determine the specific action to perform. If the      action is **fx\_formatDateTime**, it calls the **formatDateTime** method. \
\
4\. This method extracts a datetime string from the input map, parses it, and constructs a datetime       object. The formatted datetime is then returned in a map with the key 'result'.<br>

**Test Class:**\
\
@isTest

private class CustomDateTimeFormatterTest {

&#x20;   @isTest

&#x20;   static void testCustomDateTime() {

&#x20;       CustomDateTimeFormatter formatter = new CustomDateTimeFormatter();

&#x20;       String action = 'fx\_formatDateTime';

&#x20;       Map\<String, Object> params = new Map\<String, Object>();

&#x20;       List\<Object> inputParams = new List\<Object>{'2024-02-21 09:58:57'};

&#x20;           params.put('input', inputParams);

&#x20;       Object result = formatter.call(action, params);

&#x20;       Map\<String, Object> resultMap = (Map\<String, Object>) result;

&#x20;       Datetime formattedDateTime = (Datetime) resultMap.get('result');

&#x20;       System.assertEquals(2024, formattedDateTime.year());

&#x20;       System.assertEquals(2, formattedDateTime.month());

&#x20;       System.assertEquals(21, formattedDateTime.day());

&#x20;   }

}\
\
**How to use Custom Function in the Action**\
\
**Syntax :-** Class:fx\_methodName(/path)

**Example :-** CustomDateTimeFormatter:fx\_formatDateTime(/StartDate)\
\
In the value side, you can use the above syntax to set the value accordingly.<br>

<figure><img src="https://1271267903-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F899iGp7icc9A7KXck3HI%2Fuploads%2F8I0d1KOQPOiH2iGY8fSH%2Fimage.png?alt=media&#x26;token=80c9d819-a40a-4280-a9ef-caa096020c26" alt=""><figcaption></figcaption></figure>

<br>

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://200ok.gitbook.io/200ok-documents/user-manual/custom-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
