- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 10:12 AM
How do I get a record count, and then push that value to another table? Running a fix script against the location table and I can retrieve the record count using getRowCount, but I can only display that value in the logs. I cannot assign it to a variable or use it to push to another table. I want to push that value to another table. For example
var queryString = "sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()";
var grq = new GlideRecord('cmn_location');
grq.addEncodedQuery(queryString);
grq.query();
gs.log('Locations, row count is: ' + grq.getRowCount());
if (grq.getRowCount() > 0) {
gs.log('Locations: Number of Locations created today: ' + grq.getRowCount());
var grq = new GlideRecord('incident');
grq.initialize();
grq.caller_id.setValue('gfgdfgdfgfdgdfgfdg');
grq.opened_by = 'gdfgdfgfdgfsdgdfgfg';
grq.contact_type = 'Monitoring';
grq.impact = '4';
grq.urgency = '4';
grq.location.setValue('ergergergrgwtr);
grq.assignment_group = '5f65b1a01b0bb348fc82773bdc4bcbbd';
grq.short_description = grq.getRowCount() + ' Locations created today';
grq.description = grq.getRowCount() + ' Locations created today';
grq.cmdb_ci = 'cdswefqwefq4553245';
grq.u_request_type = 'Service Restoration';
grq.category = 'Interface';
grq.subcategory = 'Issue';
grq.insert();
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 10:28 AM
It's because you're using the same variable name for both queries. Change that incident query to grq2 instead of grq.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 10:17 AM
Try the following:
var queryString = "sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()";
var grq = new GlideRecord('cmn_location');
grq.addEncodedQuery(queryString);
grq.query();
gs.log('Locations, row count is: ' + grq.getRowCount());
if (grq.getRowCount() > 0) {
gs.log('Locations: Number of Locations created today: ' + grq.getRowCount());
var grq = new GlideRecord('incident');
grq.initialize();
grq.contact_type = 'Monitoring';
grq.impact = '4';
grq.urgency = '4';
grq.assignment_group = '5f65b1a01b0bb348fc82773bdc4bcbbd';
grq.short_description = grq.getRowCount() + ' Locations created today';
grq.description = grq.getRowCount() + ' Locations created today';
grq.u_request_type = 'Service Restoration';
grq.category = 'Interface';
grq.subcategory = 'Issue';
grq.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 10:24 AM
The value pushed the the incident is zero. Whereas in the logs I can see it shows 2

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 10:25 AM
Have you tried doing grq.getRowCount().toString()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-10-2019 10:26 AM
Tried that just now, still getting zero