Handle Integer in GlideRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:01 PM
Hi,
I am trying to get the next number based on RowCount output. Here is the script
var existingCI = new GlideAggregate('cmdb_ci');
existingCI.addQuery('company','81fca4cbac1d55eb355b4b6db0e3c80f');
existingCI.addAggregate('COUNT');
existingCI.query();
var records = 0;
if (existingCI.next()) {
records = existingCI.getAggregate('COUNT');
gs.info(records);
if(records> 0) {records= records+1;} else {records= records+2;}
gs.info(records);
}
Script output:
*** Script: 102
*** Script: 1021
The expected output is:
*** Script: 102
*** Script: 103

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:22 PM
Seems you are appending, rather you should convert to integer and sum the numbers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:26 PM
Hi,
Use this script:
var existingCI = new GlideAggregate('cmdb_ci');
existingCI.addQuery('company','31bea3d53790200044e0bfc8bcbe5dec'); // This is my company sys_id. Replace your sysid
existingCI.addAggregate('COUNT');
existingCI.query();
var records = 0;
if (existingCI.next()) {
records = existingCI.getAggregate('COUNT');
gs.info(records);
if(records> 0) {
records= parseInt(records)+7;
} else {
records= parseInt(records)+2;
}
gs.info(records);
}
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-10-2019 12:44 PM
Try below
var existingCI = new GlideAggregate('cmdb_ci');
existingCI.addQuery('company','81fca4cbac1d55eb355b4b6db0e3c80f');
existingCI.addAggregate('COUNT');
existingCI.query();
var records = 0;
if (existingCI.next()) {
records = existingCI.getAggregate('COUNT');
records =parseInt(records,10)
gs.print(records);
if(records> 0) {records= records+1;} else {records= records+2;}
gs.print(records);
}