Cannot figure out why form field does not update at end of script

Digit
Kilo Guru

I have been pulling my hair out trying to figure why my scheduled job script is not updating the actual form field. I am  calculating the duration a form is in a state on a daily basis, and adding the new value to the existing value (running tally).

The script functions as expected up until the line where I am trying to push the aggregated value to the form field (u_time_in_assigned), which is an integer type. I've checked formatting (using parseInt and math.round) with no luck, as well as setValue(), and just doing an x=y.

The final log statement displays the expected value, but when I look at the actual form, the value does not get updated. 

Really appreciate any assistance with this!!

var arch = new GlideRecord('u_architecture_request');
arch.addEncodedQuery('active=true^sys_class_name=u_architecture_request^stateIN22');
arch.query();

while (arch.next()) {
    //calculate time since last run and add to duration
    var initTime = arch.u_time_in_assigned;
    gs.log('Number: ' + arch.number.getDisplayValue() + '\nOld time in assigned: ' + initTime + '\nu_assigned_state: ' + arch.u_assigned_state, 'test');

    // Calculate the new duration based on the 24 hour weekdays excluding holidays schedule
    var startDate = new GlideDateTime('arch.u_assigned_state');
    var endDate = new GlideDateTime();
    var schedule = new GlideSchedule('563653c8db670bc09b65v53a8c96194d', 'UTC'); // loads 24 hour weekdays excluding holidays schedule
    arch.u_assigned_duration = schedule.duration(startDate, endDate);

    //update the aggregated duration after converting from milliseconds to minutes
    var u_time = (arch.u_assigned_duration.dateNumericValue() / (60 * 1000)) + initTime;
    var uTime2 = parseInt(u_time);
    arch.setValue(arch.u_time_in_assigned, uTime2);

    gs.log('Number: ' + arch.number.getDisplayValue() + '\nNew time in assigned: ' + arch.u_time_in_assigned, 'test');
    arch.update();
}
1 ACCEPTED SOLUTION

OlaN
Giga Sage
Giga Sage

Hi,

I believe this is the error

// replace this
  arch.setValue(arch.u_time_in_assigned, uTime2);

// with this
  arch.setValue('u_time_in_assigned', uTime2);

View solution in original post

5 REPLIES 5

🙂