Help with Background Script to update large amount of records

William McKiern
Tera Contributor

Hello,

 

 I have written the script included with this post with some help from other forum posts dealing with a similar topic. The code is returning all the desired values and otherwise seems to work as desired except it is not actually performing any updates. The goal of the code is to calculate a duration within a schedule (in this case the "8-5 working hours holidays excluded" schedule) and then populate that value in the "Business Duration" field for every record that is currently in the "Close" state. I have spent a lot of time scouring google trying to find and answer and am stumped. I would really appreciate some fresh perspective from the community on this. Thanks in advance!

 

 

 

        var schedule = new GlideSchedule('dfcc2e281b58e890c8da64ade54bcb52');
        var apInq = new GlideRecord('x_g_ngr_account_pa_ap_inquiries');
        apInq.addQuery('state', '3');
        apInq.query();
        gs.info('Matching AP Records ' + apInq.getRowCount());
        while (apInq.next()) {
			apInq.setWorkflow(false); 
            var opened = new GlideDateTime(apInq.opened_at.getDisplayValue());
            var closed = new GlideDateTime(apInq.closed_at.getDisplayValue());
            var duration = schedule.duration(opened, closed);
            //gs.info('Duration is ' + duration.getDurationValue());
           //gs.info(apInq.number);
            apInq.business_duration = duration.getDurationValue();
            apInq.ticket_duration = duration.getRoundedDayPart() + " day(s)";
            apInq.update;
        }

 

 

2 REPLIES 2

Karan Chhabra6
Mega Sage
Mega Sage

Hi @William McKiern ,


Please replace the last three lines of your code with the code below and test again.

apInq.setValue('business_duration' , duration.getDurationValue());
apInq.setValue('ticket_duration' , duration.getRoundedDayPart() + " day(s)");
apInq.update();

 

If this helped, please mark my response as helpful.

 

Thanks!

 

 

Kamil Smusz
Kilo Sage

hi @William McKiern ,

 

Try replace apInq.update; with below

apInq.update();