Ahh... Now that I after a while look at your pictures I think I get what you after.. sometimes you just stares blind on something 😃



Something like this and it only does 2 server calls.




var count = 1; //Get the counter read




var gr = new GlideRecord('change_task'); //Fetch the records we want to update


gr.orderBy('NAME OF YOUR TASK FIELD');


gr.orderBy('sys_updated_on');


gr.query();



var gr2 = new GlideRecord('change_task'); //Fetch another set of record so we can compare to the "next" record


gr2.orderBy('NAME OF YOUR TASK FIELD');


gr2.orderBy('sys_updated_on');


gr2.query();


gr2.next();//Skip ahead one record so gr2 always is one record ahead of gr



while(gr.next()){


if(!gr2.next()){//If there isn't a next record in gr2, gr is the last one


gr.setValue('u_last',true);//To handle the last record


}


gr.setValue('u_order',count);


//Check if the is is the last one and reset the counter if that is true.


if (gr.getValue('NAME OF YOUR TASK FIELD') != gr2.getValue('NAME OF YOUR TASK FIELD')){


gr.setValue('u_last',true);


count = 1;


}


//If it isn't the last one, add 1 to the counter


else {


count++;


}


gr.autoSysFields(false); //Guess you don't want the sys_updated_on field to be updated when you run your script.


gr.update();


}



//Göran


View solution in original post