Time Card Total Calculation

Elias11
Giga Expert

Hi Experts

I have a really weird issue.

I am working on the Time Card Module and Table.

I have a list where it is showing me my Current Time for this week.

and I am listing the Total of the Days.

What I want is to not allowing to add more than 8 hours per one day on this list.

e.g. on Monday shouldnt be more than 8 as total.

I have created a Business Rule on Time Card to run "After"   when Sunday changes.

in this BR i am GlideAggregate with this list.

All is working fine , the calculation is working but when I need to reset the field (Sunday) if Total more than 8. with:

        current.sunday = 0;

        current.update();

sometime it is working and sometime it isnt reseting to 0.

Andybody has an idea?


find_real_file.png

1 ACCEPTED SOLUTION

I found the solution my self



As the current.update() on After BR is not working properly I had to do a workaround and this is working all the time



this my solution Code:


var gr = new GlideRecord('time_card');


        gr.addQuery('sys_id', current.sys_id);


      gr.query();  


    while (gr.next()) {


    gr.sunday = previous.sunday;


    gr.update();


View solution in original post

3 REPLIES 3

Elias11
Giga Expert

More weird is that I have debug this BR and even it is not working on the debug it is showing me all the time that the record current.sunday is reset to 0



sunday: 5 => 0


sunday: 4 => 0


sunday: 4 => 0


I found the solution my self



As the current.update() on After BR is not working properly I had to do a workaround and this is working all the time



this my solution Code:


var gr = new GlideRecord('time_card');


        gr.addQuery('sys_id', current.sys_id);


      gr.query();  


    while (gr.next()) {


    gr.sunday = previous.sunday;


    gr.update();


JusCuz
Tera Guru

On a side note, you want to be very wary of using current.update() in business rules....especially After business rules. See section four in this article: Business Rules Best Practices - ServiceNow Wiki