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 Writing Code for Server Scripts and 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 - 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

Server Scripts Example - Update Credit Score of a Contact

This article gives you an example of how you can update the credit score of a Contact using Server Scripts.
A
Abdul Sameer
19 Apr, 2024 - Updated  11 months ago

Update the Credit Score of Contact

Consider a company CreditX is a leading financial services company specializing in providing credit solutions. They assess creditworthiness accurately, ensuring fair lending practices. They provide services like personal loans and credit cards.

To manage their sales and support they use CRM. Their customers are created as Contacts in CRM. To provide a better offer to customers they need the credit scores of their customers.

This can be done easily with Server Scripts and Jobs.

To achieve this, you must create a process or workflow and add Server Script action.

 
async function main(record, user) {
    //From record get tax identification number
    var tin = record.cf_tax_identification_number;
    if(tin) {
        //Send request to credit score provider
        try {
            var response = await vtap.macro.http.get(
                'https://www.myprovider.com/api/creditscore', {
                headers: {
                    Authorization: 'Basic XXXXXXXXXXXXXXXX'
                },
                qs: {
                    tin: tin
                }
            });
            //Check request is successful by request status code
            if(response && response.status == 200 && response.body) {
                //Parse JSON response
                var scoreData = JSON.parse(response.body);
                if(scoreData && scoreData.credit_score) {
                    //If credit score is available, set it to credit score field
                    record.cf_credit_score = scoreData.credit_score;
                }
            }
        } catch(error) {

        }
    }

    //Return record data back by setting credit score. Changed field value will be updated in record
    return record;
}


Explanation
  • When a record is saved, this action will trigger.
  • Getting tax identification number from record data (custom field)
  • If TIN is there, send a GET API request to the credit score provider service with TIN in the query string.
  • On request, the basic authentication header is set for authorization.
  • If the API request is successful, get the credit score from the response.
  • Set the credit score to the field.
  • Return record data back.
  • Since the credit score field value is changed, workflow or process will update it to the record.
Related articles
Server Scripts & Jobs Overview Using Custom Server Scripts in Processes, Workflows, and Approvals Running Custom Background Tasks with Vtiger Server Jobs Writing Code for Server Scripts and Jobs Server Scripts Example - Contact Email Validation and Data Enrichment
Home Privacy Policy Terms of Service Security Center Policy & Legal Center Contact Us
© Copyright 2025 Vtiger. All rights reserved.
Powered by Vtiger
Facebook Twitter Linkedin Youtube