Script for calculation

beycos
Tera Contributor

Hello SN community,

I currently have two tables. I want to calculate the total of the "< 10 min" field for records with the same reference number in the first table ('x_1002836_f64_c'). I would like to display this total in the 'Total of < 10 min' field in the second table. In the first table with the SAME reference table  total of "< 10 min" should be in the second table in total 10min.

(function calculatedFieldValue(current) {
    var total = 0;

    // Check if the current record exists and has a valid reference number
    if (current && current.reference_number) {
        // Create a GlideAggregate query to calculate the sum of the "u_10_min" field
        var aggregate = new GlideAggregate('x_1002836_f64_c');

        // Group by the reference field
        aggregate.addQuery('reference_number', current.reference_number);

        aggregate.addAggregate('SUM', 'u_10_min'); // Calculate the SUM of the "u_10_min" field

        aggregate.query();

        if (aggregate.next()) {
            // Update total with the sum of "u_10_min" for the same reference field value
            total = aggregate.getAggregate('SUM', 'u_10_min');
        }
    }

    return total;
})();
Unfortunately This script is not working.
I would be grateful if you could assist me.
Thanks in advance.
1 REPLY 1

Joe Wong
Tera Guru

Hi Beycos,

 

Looks like there is a lot of traffic to your question, but maybe, like others, I am a bit confused to what you are actually trying to do.  Maybe can you give an example of what the source table should look like and what the resulting table should end up with.

 

Just trying to help.