Scripts

The platform6.scripts service allows you to write and run the business logic of your application.

Read the user guide of the Scripts service to discover its operating mode.

List the scripts identifiers

This resource returns the list of the scripts identifiers.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) list.ids
platform6.request.user The email address of the user sending the message

Headers of the response

Header’s key Description
platform6.response.value The list of identifiers

Example

def cm = [ headers: [ 'platform6.request.action': 'list.ids' ] ]

print service.request('platform6.scripts', cm).headers['platform6.response.value']

The response will be:

[
    {
        "appKey": "",
        "name": "AuthTokenCall"
    },
    {
        "appKey": "",
        "name": "AWFCall"
    },
    {
        "appKey": "ondiflo",
        "name": "_CallCall"
    },
    {
        "appKey": "",
        "name": "FormProcessor"
    }
]

Add a script

This resource creates a new script if there is no script with the same identifier, otherwise, it does nothing.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) add
id The identifier of the script (required)
description The description of the script (required)
main.content The main file of the script
platform6.request.user The email address of the user sending the message

The new script will be verified before upsert.

The last author of the modification will be the user who sent the common message.

The content mode will automatically be set to NONE.

Warning

The identifier and the description must validate the service’s item rules.

Headers of the response

Header’s key Description
platform6.response.status true if the item was created, false if it already exists

Example

In this example, the script will add in the pipeline a variable with the key response and the value Hello world.

For more information about the method pipeline.put, read the following page Pipeline.

import groovy.json.JsonOutput

def cm = [
    headers: [
        'platform6.request.action': 'add',
        'id': 'my_new_script',
        'description': JsonOutput.toJson([EN: 'A new script', FR: 'Un nouveau script']),
        'main.content': 'pipeline.put("response", "Hello world")'
    ]
]

print service.request('platform6.scripts', cm).headers['platform6.response.status']

The response will be true if the script is validated and created. If a script with the same id already exists, it will return false.

If a field of the input is incorrect, it will throw an exception.

{
    "message" : "Unexpected exception adding a new script 'my_new_script': the parameter 'description' is missing.",
    "stackTrace" : [
        "com.amalto.b2box.core.api.B2boxException: Unexpected exception adding a new script 'my_new_script': the parameter 'description' is missing.",
        "    at com.amalto.service.scripts.ScriptsService.notifyRequestMessage(ScriptsService.java:173)",
        "    at com.amalto.b2box.core.impl.servicecomponent.AbstractServiceComponent.onCommonMessage(AbstractServiceComponent.java:688)",
        "    at com.amalto.b2box.core.impl.platform.messagebus.BusQueueController$ServiceQueueRunner.run(BusQueueController.java:183)",
        "    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)",
        "    at java.util.concurrent.FutureTask.run(FutureTask.java:266)",
        "    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)",
        "    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)",
        "    at java.lang.Thread.run(Thread.java:748)"
    ]
}

Execute a script

This resource executes a specific script.

Parameters

Headers of the request

Header’s key Description Value
platform6.request.action The action to perform (required) execute
id The identifier of the script (required)
platform6.request.user The email address of the user sending the message

The author of the script’s execution will be the user who sent the common message.

Headers of the response

The response common message can contain headers or attachments added by the script.

Example

The script’s content of this example is in the example above.

def cm = [
    headers: [
        'platform6.request.action': 'execute',
        'id': 'my_new_script'
    ]
]

print service.request('platform6.scripts', cm).headers.response

The output will be:

Hello world