Home  >   FAQs   >  how to write a server script to update the credit score of a contact?
FAQs in this section

how to write a server script to update the credit score of a contact?

Table of Contents
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 JobsTo do this, you must create a Process or Workflow and add a 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;

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