Home >
VTAP Platform
> Writing Code for Server Scripts and Jobs
Articles in this section
Server Scripts & Jobs Overview
Using Custom Server Scripts in Processes, Workflows, and Approvals
Running Custom Background Tasks with Vtiger Server Jobs
Helper Method for Server Scripts and Jobs - Debugging
Helper Method for Server Scripts and Jobs - HTTP Request
Helper Methods for Server Scripts and Jobs - Vtiger REST API
Server Scripts Example - Contact Email Validation and Data Enrichment
Server Scripts Example - Update Credit Score of a Contact
Server Scripts Example - Calculate Organization Outstanding Invoice Amount
Server Scripts Example - Set Case SLA by Created Day
Server Jobs Example - Importing Daily Leads from a File
Server Jobs Example - Update Stocks Weekly in Warehouse System
Server Side Scripts & Jobs User Guide
Writing Code for Server Scripts and Jobs
This article gives you a checklist on how to write codes for the Server Scripts and jobs in Vtiger CRM.
A
Abdul Sameer
19 Apr, 2024 - Updated
7 months 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, String, etc.
- You can also use helper methods provided like HTTP request methods, Vtiger’s REST API methods, and log methods for debugging.
Helper Methods
Following are a few helper methods provided which are available by default to make your work easier:
- Debugging methods: To make coding easier and debug, there is a 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 services, methods are available (vtap.macro.http)
- Vtiger REST API methods: To make REST API calls to the CRM instance, you can use vtap.macro.ws
To learn more about helper methods and see code in action, refer to the below examples
- Contact Email Validation and Data Enrichment
- Updating the Credit Score of Contact
- Calculate Organization outstanding Invoice amount
- Set Case SLA by created day
- Importing Daily Leads from the Website to CRM
- Update Available Stocks to Warehouse System Weekly
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 requests and Vtiger's REST API methods.
- Use try-catch to handle errors from requests 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