- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2016 11:34 AM
Hi,
I would like to know how to get the current element/record in a glideRecord query.
Here is my current script:
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2016 02:00 PM
//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 = '';

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2016 11:39 AM
So you only want to decrement current record which you are on right?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2016 11:41 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2016 11:59 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2016 05:25 PM
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.