- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2014 10:31 AM
I am attempting to run the following code in a test workflow:
var gr = new GlideRecord('sys_template');
var query_name = 'RBA - Network - KMTC VIP';
gr.addQuery('name', query_name);
gr.query();
if (gr.hasNext())
{
workflow.info('hasNext() says we have a next() available');
workflow.info('the reported name (should be empty): "' + gr.name + '"');
// why is this throwing an error?
gr.next();
workflow.info("next() call has succeeded - we won't get to here");
}
When the code gets to the gr.next()call, the workflow fails (the Run Script block turns red), and the following error shows up in the context log:
Execption in Activity Handler:Log Object
Object
lineNumber: string = 16
sourceName: string = <refname>#17(eval)
name: string = TypeError
message: string = is not a function.
This appears to be table-specific, as changing to a different table (such as incident or change_request) works correctly. I'm asking my admin to look into it, but we're all new to SN, so I figured I'd see if anyone else has seen this behavior before, and what it might mean. We have a theory it may be something around permissions, but that is at best a moderately informed conjecture.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2014 01:53 PM
For what it's worth, this code exhibits the exact same problem:
var gr = new GlideRecord('sys_template');
gr.query();
gr.next();
It turns out that there is a field in sys_template called 'next'. If we call gr._next(), it works properly. The lesson is to check the fields in the table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2014 11:44 AM
I think the issue is not because gr.next() but because if using gr.name before gr.next()
You still don't have the real record to point to, so gr.name will be throwing an exception. Can you re-arrange them and try?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2014 12:01 PM
No, the call to gr.name() works properly and returns an empty string (or undefined -- doesn't really matter). The same code without the call to gr.name() fails in the same way, at gr.next(). The same code on a different table works correctly (name is reported as an empty string, and gr.next() succeeds).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2014 12:47 PM
I haven't seen gr.next() used this way before. I'm not saying if it should or shouldn't work this way; I am saying there are more standard ways of using the .next() method.
gr.next() is usually used to increment to the next record within a loop.
Try:
var query_name = 'RBA - Network - KMTC VIP';
var gr = new GlideRecord('sys_template');
gr.addQuery('name', query_name);
gr.query();
if (gr.hasNext()) {
workflow.info('hasNext() says we have a next() available');
workflow.info('the reported name (should be empty): "' + gr.name + '"');
// why is this throwing an error?
while(gr.next()) {
workflow.info("next() call has succeeded - we won't get to here");
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2014 01:23 PM
I would still think there is something weird going on here, because gr.next() is equivalent to while(gr.next()) with only one record, may be a hi ticket might help!