Code Services

Content:
1. Create new Service
2. Code Editor
3. Settings
4. Triggers
5. Timers
6. Failed Runs
7. Delete, Discard, and Save

Creating a new Code Service

Click “+ Add Code” from the to open the “Create New Service or Library” modal.

New Code Service

This allows you to use the code libraries to build code. Give the code service a one word name for the system to refer to and click Create.

New Code Service

Code Editor

  1. Add code to the window to run
  2. Pick code libraries to use in your code (log is added by default). Make sure to choose the clearblade library to interact with the ClearBlade platform
  3. Edit test parameters then Save and Test code
  4. Test results will then appear
  5. Turn the log toggle on to keep track of the code results

Debugging

To debug your code service, ClearBlade provides as simple, but flexible logging facility
1. Make sure the log toggle is on

2. When you create/edit your code service, you can embed log() calls in strategic places to monitor execution progress

3. You can then run/test the code service. This window should pop up after the service executes:
4. There will be a list of logs starting with the most recent one to go back to

5. Finally, when you have finished you debugging and your service is working perfectly, You can turn off logging by switching the toggle.You do not have to remove the logs from the code. They just become noop statements.

Settings Pane

Select roles that should be able to run the code service

Advanced Settings

“Run as a user”- will let the developer user see what the end user see

“Concurrency”-limits how many instances that can run at the same time

“Execution timeout”-limits how long the code service execution can run

“Auto restart”- restart service automatically if there is a crash

“Currently running”-shows what code is running and can be refreshed.

Trigger Pane

Add Trigger

Click on “+ Add Trigger”

Enter a name, source, and action and click “Create Trigger”

Update Trigger

There is only a couple of items that can be edited on the trigger.
Data: Collections
Messaging: Topics
User: Users
Device: Devices

Click “Update Trigger” after making the edit

Delete Trigger

Click “Delete” on the right of the trigger and click “confirm” when prompted.

Timers Pane

“Name”- add a label to the timer
“Start Date”-add a date and time to start the run
“Run”- select how many times the code should run
“Description”- provide a description for the timer

Click “Create Timer” when you are finished

Click “Update Timer” to make updates (except name) and “Delete” to delete timer.

Failed Runs

If a run fails, a banner will show. If you click on “view” on the banner to see what failed.

Delete, Discard, and Save

  1. Click “Delete Service” and a prompt will appear to verify deletion.

  2. Click “Discard Changes” to delete changes you made in the session. It will take you back to the homepage without a confirmation prompt.

  3. Click “Save” to save changes made to the service.