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.
Abdul Sameer
8 May, 2026 - Updated
5 months ago
Intoduction
Scripts and Jobs in Vtiger CRM are written using JavaScript (ES5). These scripts are used to automate actions, update records, integrate with external services, and perform custom operations in the CRM.
All code must be written inside the main() method. Code written outside the main() method will not execute. The main() method is invoked automatically during execution, so you do not need to call it manually.
You can use standard JavaScript methods such as:
- Math functions
- JSON methods
- String methods
- Array methods
You can also use helper methods provided by Vtiger for:
- Debugging
- HTTP requests
- REST API operations
Script Structure
Use the following structure while writing Scripts and Jobs:
| async function main() { // Write your code here } |
Helper Methods
The following helper methods are available by default.
Debugging Methods
To debug scripts and print logs during execution, use the log() method.
Logs can be viewed:
- During test execution
- In Script logs
- In Job logs
You can also use JavaScript console methods for debugging.
Example
| async function main() { log("Script execution started"); } |
HTTP Request Methods
To send HTTP requests to external services, use:
Example
| async function main() { let response = await vtap.macro.http.get({ url: "https://example.com" }); log(response); } |
Vtiger REST API Methods
To make REST API calls to the CRM instance, use:
Example
| async function main() { let contact = await vtap.macro.ws.retrieve("Contacts", "12x1"); log(contact); } |
Example Use Cases
Below are a few examples of Scripts and Jobs:
- Contact Email Validation and Data Enrichment
- Updating the Credit Score of Contact
- Calculate Organization Outstanding Invoice Amount
- Set Case SLA by Created Day
- Import Daily Leads from Website to CRM
- Update Available Stocks to Warehouse System Weekly
Constraints
Keep the following constraints in mind while writing Scripts and Jobs.
| Feature | Limitations |
| Code Structure | Code must be written inside the main() method. |
| Server Script Execution | Server scripts can run for up to 15 seconds and use a maximum of 32 MB of memory. |
| Hourly Server Jobs | Hourly jobs can run for up to 90 seconds with 128 MB of memory. |
| Other Server Jobs | Other server jobs can run for up to 4 minutes with 128 MB of memory. |
| Scheduled Workflows and Processes | Scheduled workflows or processes cannot use server scripts. |
| Daily Execution Limits | Daily execution limits apply to scripts and jobs. If exceeded, they run the next day or are skipped. |
| Restricted JavaScript Methods | Methods such as setTimeout, setInterval, and eval are restricted. |
| External Module Imports | Using require or import is not supported. |
| Promise Handling | Use await instead of .then() for HTTP requests and REST API methods. |
| Error Handling | Use try-catch blocks to handle errors. |
| HTTP Requests | Only HTTPS websites with valid SSL certificates are supported. |
| Restricted URLs | Direct IPs, localhost, and Vtiger domains are restricted except the CRM instance URL where the script is executed. |
Reference