unable to find the error

ayushchandra202
Tera Contributor

I had made an application in studio for Leave Management System. While applying the business rule I wrote the below script. which is not giving me the desired result. unable to find the error. please help.

 

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var gr= new GlideRecord('x_1104314_lms_leave_calculator');
    gr.addQuery('country.name', current.location.country);
    gr.query();
    if (gr.next()){

        if(gr.leave_assignment == 'y'){

            var gtd = new GlideDateTime();
            var currentMonth = gtd.getMonthLocalTime();
            var monthsLeft = 12 - currentMonth;
            var perMonth = gr.leaves/12;
            var totalLeaves = perMonth * monthsLeft;


            var leaveBucket = new GlideRecord('x_1104314_lms_leave_bucket');
            leaveBucket.initialize();
            leaveBucket.leave_type = gr.leave_type;
            leaveBucket.accrued = totalLeaves;
            leaveBucket.balance = totalLeaves;
            leaveBucket.taken = 0;
            leaveBucket.employee = current.sys_id;
            leaveBucket.insert();
        }
        else if (gr.leave_assignment == 'm'){
            var perMonthM = gr.leaves/12;
            var leaveBucketm = new GlideRecord('x_1104314_lms_leave_bucket');
            leaveBucketm.initialize();
            leaveBucketm.leave_type = gr.leave_type;
            leaveBucketm.accrued = perMonthM;
            leaveBucketm.balance = perMonthM;
            leaveBucketm.taken = 0;
            leaveBucketm.employee = current.sys_id;
            leaveBucketm.insert();
        }
    }

})(current, previous);
1 REPLY 1

Ankur Bawiskar
Tera Patron
Tera Patron

@ayushchandra202 

unless you add logs and debug you won't know where it's failing

what did you add and debug?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader