Home  >   VTAP Platform   >  Server Scripts Example - Set Case SLA by Created Day

Server Scripts Example - Set Case SLA by Created Day

This article gives you an example of how you can set Case SLA by created day using Server Scripts.
A
Abdul Sameer
19 Apr, 2024 - Updated 27 days ago
Table of Contents

Set Case SLA by Created day

Consider CompanyX provides marketing services to multiple organizations. If any organization has any issue with the service provided, they reach out to the support. For support also CompanyX uses CRM.

CompanyX is very concerned about their client and wants to make sure timely resolution is provided to their client. For that they use SLAs. But their support team works 24 x 5. If any client reports an issue over the weekend, SLAs are being violated. To avoid that, they want to set the SLA for tickets created over the weekend to a different one having higher targets.

To achieve this, you must create a process for ticket creation and Server Script action. Check if created time is weekend, then set SLA as Weekend SLA.

 
async function main(record, user) {
    //Create Date object from case created datetime
    var dateObj = new Date(record.createdtime);

    //Check if day number is 0 (Sunday) or 6 (Saturday)
    if(dateObj.getDay() === 0 || dateObj.getDay() === 6) {
        try {
            //Fetch weekend SLA id using rest api query operation
            //Note: SLA id can be hard coded as well instead of fetching from api since id will not change once created.
            //That will avoid additional api request and reduce execution time
            var slaResult = await vtap.macro.ws.query("SELECT id FROM SLA WHERE policy_name = 'Weekend SLA' LIMIT 1;");
            if(slaResult && slaResult.success && slaResult.result && slaResult.result.length) {
                var wsSlaId = slaResult.result[0].id;
                var wsSlaIdParts = wsSlaId.split('x');
                var slaId = wsSlaIdParts[1];

                //Set slaid to record
                record.slaid = slaId;
            }
        } catch(error) {

        }
    }

    return 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.