
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 02:26 AM
Dear Community,
a simple question from a newbie.
I was asked to copy/paste bookmarks from one user to another and I was successful with that, however, I came up with one question.
Why two 'while' loops can't be executed within one GlideRecord query?
Here is the script. It is supposed to copy/paste the bookmarks and then show me the list of bookmarks belonging to the main user. Only the first 'while' is always executed.
Thank you 🙂
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-08-2020 02:35 AM
Hi,
probably because when the 1st while loop ends the gliderecord object refer to last record for that query and thereafter it won't iterate over again as no records exists for this query
Example below:
var gr = new GlideRecord('incident');
gr.addQuery('caller_id', gs.getUserID());
gr.setLimit(10);
gr.query();
gs.info(gr.getRowCount());
while(gr.next()){
gs.info('First while '+gr.number);
}
gs.info('After 1st while ends '+ gr.number);
while(gr.next()){
gs.info('Second while '+ gr.number);
}
When the 1st while loop ends; it refers to the last record;
So it still prints the INC number After 1st while; but there are no records after this hence it fails to print the logs for 2nd while
Output:
If my answer solved your issue, please mark my answer as ✅ Correct & 👍Helpful based on the Impact.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2020 03:27 AM
Is this question resolved or you need some more assistance?
Let me know if that answered your question. If so, please mark my response as ✅ correct & 👍Helpful so that others can benefit from similar question in future.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader