LAC JavaScript Function endpoints

Blog Post created by banty01 Employee on Mar 9, 2017

In the latest release (3.1.1) of CA Live API Creator (LAC), we introduced a new type of user defined endpoint labeled as 'Function'.  A user function is a named endpoint written in JavaScript that can have optional named parameters. In reality, there are 2 distinct types of these functions.  The first is a top level function - that is - a named endpoint (similar to a JavaScript Resource). These functions can be called by other resources, events, or used in rules.  These JavaScript endpoints have access to user defined and import JavaScript libraries as well as access to 3rd party Java JAR files.  The other type of function is tied to the a specific row on a table, view, or normal resource.  For example, if you create a function 'giveRaise' with a parameter 'percentRaise' and specify that it is tied to the employee table - then this endpoint can only be called using the url below:


Note that the {pkey} is the defined primary key for the employee table. Now, inside the JavaScript - you have full access to the 'row' object for this employee/{pkey} record.  You simply access the row variable and the row is updated back to the database.

var theRaise = parameters.percentRaise * (row.Salary/100); 
row.Salary += theRaise;  // runs logic, persists change row(s) to database...
return [ {"status": "Success"}, {"raise": theRaise} ];


See the documentation for information on this amazing new feature.  The LAC command line utility has also been updated to support this new feature.


$lacadmin function --help

  Usage: function [options] <list|delete|export|import>

  Administer Functions for current project.


    -h, --help                       output usage information

    --ident [ident]                  This is the ident of the function

    --project_ident [project_ident]  The project ident that will be used

    --file [fileName]                [Optional] Name of file to import/export