Home  >   VTAP Platform   >  Server Scripts Example - Update Credit Score of a Contact

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 8 months ago
Table of Contents

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.
Was this article helpful?
0  out of  0  found this helpful.
Comments 0
Be the first to comment
© Copyright 2023 Vtiger. All rights reserved.