How do I get the current record in a glideRecord query?

lightblu
Mega Expert

Hi,

I would like to know how to get the current element/record in a glideRecord query.

Here is my current script:

find_real_file.png

The

gr.x_prgm_red_team_te_u_integer_1 -= 1;

part is decrementing all the records in gr which get returned from the query.

I want something like:

while(gr.hasNext()){

     

        //conditional

        if(gr.peekNext().x_prgm_red_team_te_u_integer_1 > currOrder){

                  //decrement only the specific record gr.next is on, not every record in gr

                  gr.next().x_prgm_red_team_te_u_integer_1 -= 1;

        }

}

hence my conditional.

1 ACCEPTED SOLUTION

lightblu
Mega Expert

//grab the other records in the table x_prgm_red_team_test_app_request


var gr= new GlideRecord('x_prgm_red_team_test_app_request');


gr.addQuery('sys_id','!=',current.getValue('sys_id'));


gr.addQuery('state','1');


gr.query();



//decrement the orders for each of the other records if it is > currOrder


while(gr.next()){


  //only decrement the order for the record if it is > currOrder


  if(gr.x_prgm_red_team_te_u_integer_1 > current.x_prgm_red_team_te_u_integer_1){


    gr.x_prgm_red_team_te_u_integer_1 -= 1; //decrement


    gr.update();


  }


}




//reset the priority order for the current record to blank


current.x_prgm_red_team_te_u_integer_1 = '';


View solution in original post

5 REPLIES 5

Abhinay Erra
Giga Sage

So you only want to decrement current record which you are on right?


If that is the case, then you do not need any of this scripting. Just add these lines in there



current.state=2;


if(current.x_prgm_red_team_te_u_integer_1>1){


current.x_prgm_red_team_te_u_integer_1-= 1;


}


current.update();


No, I want to decrement multiple records.



while(gr.hasNext()){


   


        //conditional


        if(gr.peekNext().x_prgm_red_team_te_u_integer_1 > currOrder){



                  //decrement only the specific record gr.next is on, not every record in gr


                  gr.next().x_prgm_red_team_te_u_integer_1 -= 1;



        }



}




gr.hasNext iterates through records, so gr.next will be on multiple records. I want them all to be decremented if their x_prgm_red_team_te_u_integer_1 > currOrder.   Sorry, I don't think I realized that gr points to a single record and not a list of records.


Hi Ligtblu,



You need not query all records in that case. You can put additional addQuery filter to filter those records which are greater then current record.


i.e gr.addQuery('x_prgm_red_team_te_u_integer_1', '>', currOrder);



Also I am assuming you are doing this in UI action. Please let me know if that's not the case.


Please share complete script here if you are still blocked.