Custom Client-side Functions

The use of custom functions is available within the following entities and JavaScript attributes:

Entity

Attributes

Entity Form

Before Events, After Events

Entity Form Section

After Events, After Section Save

Custom Form

After Generate Events

Entity View

After Generate Js

HtmlWidget

JavaScript

To use a custom function in a JavaScript field, import the client script library by using the importClientScript method in the following format: ebs.importClientScript("");

Put the cursor between the two quotation marks (“|”) and press CTRL+SPACE. You will be suggested the available client script libraries.

Choose the client script library that defines the custom function that you want to use:

Example:

Copy
var myLib = ebs.importClientScript("myLibrary");

For usability purposes and to avoid calling the wrong methods and attributes, starting with 18.1.9, when creating script libraries and scripts you can use the ‘$m’ mechanism as follows:

  • To transform text in entity_name string, type $m.entity_name and then press the TAB key.
  • To transform text in in attribute_name string, type $m.entity_name.attribute_name and then press the TAB key.
  • To transform text in relationship_name string, type $m.entity_name.relationship_name and then press the TAB key.
NOTE  All entities and their attributes and relationships are available regardless of the current entity.

The TypeScript definition of client script library declares a specific function; therefore, the Monaco editor will suggest the function name after you type the variable name

Example:

Copy
console.log(myLib.capitalize("aWord"));

If you’re using Chrome, open the entity where the code will be run and by using the Developer tools > Console, check that the custom function returns the expected result.

Example: Print the word “AWord”.

Code execution

When retrieved, the code is transformed using the module pattern:

INPUT

Copy
var c1 = 1;
 
function A()
{
return c1;
}
 
var c2 = 2;
function B()
{
var y = function C()
{
};
return c2;
}

OUTPUT

Copy

//# sourceURL=clientScriptLib_myScript.js;
 
(function(){
 
var $export = {};
var c1 = 1;
  $export.A = function ()
{
return c1;
};
  var c2 = 2;
  $export.B = function ()
{
var y = function C()
{
};
return c2;
};
  return $export;
}());

If the module pattern is detected in the INPUT, then no transformation occurs.