Home  >   VTAP Platform   >  Writing Code for Server Scripts and Jobs

Writing Code for Server Scripts and Jobs

A
Abdul Sameer
15 Mar, 2024 - Updated 1 month ago
Table of Contents

Writing Scripts

  • Scripts & Jobs are written in Javascript (ES5).
  • As of now other programming languages are not supported.
  • All the code must be within the main() method. Anything outside this method will not execute.
  • The main method is invoked automatically and you do not need to call it.
  • You can utilize basic JavaScript methods like Math functions, JSON methods, String methods, etc.
  • You can also use helper methods provided like HTTP request methods, Vtiger’s REST API methods, and log methods for debugging.
 

Helper Methods

There are few helper methods provided which are available by default to make your work easier.

  • Debugging methods: To make coding easier and debug, there is log() method. Logs added can be viewed while test execution and in script/job logs. You can also use JavaScript's console methods to debug.
  • HTTP request methods: To send HTTP requests to external service, methods are available (vtap.macro.http)
  • Vtiger REST api methods: To make REST api calls to CRM instance, you can use vtap.macro.ws

To learn more about helper methods and see code in action, refer to below examples 

Constraints

  • Code must be within the main() method, anything outside will not be executed.
  • Server script execution has a limit of 15 sec and 32 MB of memory.
  • Hourly server jobs can run for up to 90 sec with 128 MB of memory.
  • Other server jobs can run for up to 4 mins with 128 MB of memory.
  • Scheduled workflows or processes cannot use server scripts.
  • Daily execution limits apply to server scripts and jobs. If exceeded, they run the next day or are skipped.
  • Certain JavaScript methods like setTimeout, setInterval, and eval are restricted due to potential security risks or delays in execution.
  • Importing external modules using require or import is restricted for security reasons.
  • Use await instead of .then() to handle promises from HTTP request and Vtiger's REST API methods.
  • Use try-catch to handle errors from request and REST API methods.
  • HTTP requests are only allowed for secure websites (https) with valid SSL certificates.
  • Direct IPs, localhost, and Vtiger domains are not allowed for HTTP requests, except the CRM instance URL where the script is invoked.
Was this article helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.