What is a Scriptable Function?

Scriptable Functions is our middleware platform, which allows developers to customise Layer functionality with code, unlocking unlimited potential for extending the system. Functions work well for integrations with third-party systems, or simply for modifying or supplementing the control flow of existing Layer processes.

Using code similar to JavaScript, Scriptable Functions enables developers to add business logic to most system events, including creations, record updates, and deletes with new functionality coming every week.

With that in mind, you don't have to be a developer to work on these! We recently launched Scriptable Function Templates, which means you can select from a pre-defined template, fill in some settings, and assign this to your record type.

Some sample uses of Scriptable Functions are:

  • Send a custom e-mail when a sales order is raised 📩

  • Transmit orders to a provisioning system once paid 📃

  • Send a case rating & review to a third party system ⭐

  • Update values in a record based on custom rules 🛣

  • Create workflow rules to perform actions based on triggers 🔫

  • Relay data from one API to another 🚟

The scope of Scriptable Functions is only limited by your imagination, and the functionality available on the APIs you're getting the data from, and posting to.

How can they help my organisation?

In other CRM systems, administrators would need to employ expensive developers to make basic customisations to their setup, but using our middleware, organisations can unlock the ability to write custom code snippets to carry out tasks without involving third-party developers.

How can I use them?

The process of creating a good Scriptable Function is as follows:

  • Plan It 🖋 - What do you want the function to do?

  • Code It 💻 - Spin up a new function, and test it out

  • Map It 🔗 - Associate the function with an invocation method, as outlined below

How do I implement them with existing system objects?

There are three ways to invoke Scriptable Functions on the system:

Mappings - When something happens, e.g. a lead is created, or a sales order is updated

Buttons - Strategically placed buttons to help you perform an action

Web Hooks - Invoke functions from your third party system on-demand


With the concepts out of the way, let's dive into some more detail.

How do I build a Scriptable Function?

There are two ways to code up functions on the system, by scripting it yourself (you may need a little experience in JavaScript) or customising a pre-built extension.

  • Code it yourself - Code extensions yourself in LayerScript®, an extension of the JavaScript language

  • Customise a pre-built extension - Select from a pre-built library of extensions, and plug in settings specific to your use case. If you use this, you'll be able to customise properties, but not edit the extension unless you make a copy.

Where to start?

Firstly, create your new function, and set it to Code from scratch mode.

Next, we need to select an execution method. This part's really important and determines whether your script runs straight away, or is launched into the background for processing when resources are available.

Check Run Synchronously if you want to block any further operations until your script has completed.

This is useful for operations that need to be completed immediately. If you don't mind your script running in the background (e.g. it doesn't affect any UI operations), then you can leave this de-selected.

What's in a signature?

Once you're directed over to the main editor, you'll notice a section on the left called "Default Signature"

Signature properties are the default properties that are passed in to a scriptable function when executed by default.

Having access to these means you can address the given type, get more details on it, and code up your function accordingly. e.g., if you're passed a quotation Id, you can look this up from the API using ScriptableFunctionHttpRequest, as outlined below.

LayerScript® Extensions

We've made an extension library which contains some useful functions which abstract some of the complexity of coding for some basic functions like sending system emails, or calculating rate tables.

  • ScriptableFunctionHttpRequest

  • ScriptableFunctionLookupTable

  • ScriptableFunctionLogger

  • ScriptableFunctionEncoder

  • ScriptableFunctionOAuthHelper

  • ScriptableFunctionMailer

You can read more about extensions here.

LayerScript® Templates

Layer managed templates can be loaded in order to help you get started, or form a basis of a managed integration (e.g. billing or third party).

In order to ensure that when an integration or template changes, it doesn't break your integration, we sometimes lock these scripts to prevent you from making a copy.

When using a template, it's really easy to set this up for your company! We add in snippets, which you can replace via the UI.

LayerScript® Includes

Coming soon: you'll be able to include other files to the top of your LayerScript, e.g. key stores.

Invoke LayerScript® by API

Coming soon: you can invoke Scriptable Functions by API, at this endpoint:

https://webapi.thelayer.com/swagger/ui/index#/ScriptableFunction

Testing Scriptable Functions

Check out this guide on how to test Scriptable Functions

Need more help?

Contact us via Intercom to ask questions about Scriptable Functions.

We don't currently offer support on non-Layer managed extensions, but can certainly point you in the right direction.

Did this answer your question?