Home  >   VTAP Platform   >  Using Custom Server Scripts in Processes, Workflows, and Approvals

Using Custom Server Scripts in Processes, Workflows, and Approvals

This article gives you an overview of the Server Scripts in Vtiger CRM in Processes, Workflows, and Approvals.
A
Abdul Sameer
19 Apr, 2024 - Updated 6 months ago
Table of Contents

Introduction

These are server-side code executed on a record save, approval, or rejection. They can be configured in workflows, processes, or approvals and triggered on selected actions. These scripts get record data (which is getting saved) as well as user data. If any change is made to record data and returned, changed data will be updated back to the CRM record (like an update field action).

This should be used for lighter operations like updating some field data based on complex logic, which is impossible through workflow expressions, creating records in other modules based on some logic and different mapping, sending emails through external services on certain conditions, etc. These scripts are run immediately and block the save operation. If your script takes more time, record save also will become slower.

Use Cases

  • Contact email validation and data enrichment
  • Retrieve customer credit scores from an external service and synchronize with CRM.
  • Update Organization's outstanding invoice amount
  • Create or update related record by merging CRM data and data from external source
 

Code Format

async function main(record, user) {
    //Type your code here

    return record;
}
 
  • record - Data of CRM record getting saved having record id, module name, label and all field values.
  • user - Current user data including user id, label, role, preferred currency details, timezone and all field details.
 

You can test the server scripts as soon as you write the code in workflows, processes and approvals with the option provided to select a record and verify the code. Once the test is executed, you will see a response with the text status, execution time, input, output, etc. You can see the logs once published. For Process, you will see a Logs tab beside the script and for Workflows and Approvals, you can access the logs from the List View.

Kindly refer this document to learn more about how to code, helper methods, etc.

 
Note:
  • If any field value is updated in the record and returned, that field value will be updated back in the CRM record.
  • In a record, all field values will be in internal format. While updating any field value in the record, it should be set in internal format.
  • Script execution should not take more than 15 sec and cannot consume more than 32 MB of memory else they will be killed and execution will fail.
  • Server Scripts have execution limits per day as per your CRM edition. If there are more scripts to execute, it will not run.
    • Growth Editions - 100 scripts per day
    • Professional Editions - 300 scripts per day
    • Enterprise Editions - 500 scripts per day
Was this article helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.