- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 02:38 AM
Script query return 3 numeric value for one record size value
Requirement is that , we need to calculate (add) all these and update the total through BR
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:06 AM
hi @sukran
Please try the below code its working for me i have tried the same in PDI .
Please try to run it in background first.
Thank you!
Vishakha Yadav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:10 AM
Thanks ,. this information helps and now i understand what you are struggling with.
Here is a script that will work
var totalSize = 0;
var gr = new GlideRecord("cmdb_ci_disk");
gr.addEncodedQuery("computer=5f9b83bfc0a8010e005a2b3212c9dc07"); //use sys_id of computer you want to add
gr.query();
while (gr.next()) {
gs.print(gr.size);
var s = parseFloat(gr.size.toString().replace(/GB/g, ""));
totalSize = totalSize + s
}
gs.print(totalSize);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 04:16 AM
@Anurag Tripathi the table is cmdb_ci_disk and below screenshot Im query one computer record ( 138) and the size having 3 values (500 , 15, 150) gb
Those values needs to count total as( 500+15+150)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:06 AM
hi @sukran
Please try the below code its working for me i have tried the same in PDI .
Please try to run it in background first.
Thank you!
Vishakha Yadav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 06:10 AM
Thanks ,. this information helps and now i understand what you are struggling with.
Here is a script that will work
var totalSize = 0;
var gr = new GlideRecord("cmdb_ci_disk");
gr.addEncodedQuery("computer=5f9b83bfc0a8010e005a2b3212c9dc07"); //use sys_id of computer you want to add
gr.query();
while (gr.next()) {
gs.print(gr.size);
var s = parseFloat(gr.size.toString().replace(/GB/g, ""));
totalSize = totalSize + s
}
gs.print(totalSize);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 09:45 AM
@Anurag Tripathi Yes it works .. Handsoff 🙏
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-18-2024 10:13 AM
With the example screenshot you posted, what would you expect the value to be:
- 665, what you will get from the code above
- or 650.015
You will have a mix of MB, GB and TB in the individual drive sizes, which, I'm assuming, you need to account for.