- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 02:23 AM
HI Community,
I have a requirement, where i need to update the install count details in software package table.
This data is depend on the number of records present in software instances table with install on being not empty.
For example in software instances table there are 234 records with product name as google 13 out of which install on field is empty for 4 records then in software package table 230 needs to be updated in install count field
Created a scheduled job which run on daily basics
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 02:32 AM
Hi @suuriyas ,
var prod = new GlideRecord('cmdb_ci_spkg');
prod.query();
while (prod.next()) {
var rec = new GlideAggregate('cmdb_software_instance');
rec.addEncodedQuery('installed_onISNOTEMPTY^software=' + prod.sys_id);
rec.addAggregate('COUNT');
rec.query();
if (rec.next()) {
var count = rec.getAggregate('COUNT');
prod.install_count = count;
prod.update();
}
}
Try this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 02:32 AM
Hi @suuriyas ,
var prod = new GlideRecord('cmdb_ci_spkg');
prod.query();
while (prod.next()) {
var rec = new GlideAggregate('cmdb_software_instance');
rec.addEncodedQuery('installed_onISNOTEMPTY^software=' + prod.sys_id);
rec.addAggregate('COUNT');
rec.query();
if (rec.next()) {
var count = rec.getAggregate('COUNT');
prod.install_count = count;
prod.update();
}
}
Try this
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2025 02:45 AM - edited 05-14-2025 02:46 AM
Hi @suuriyas
Looks like the issue is with the encoded Query. You can use the following script:
Mark the answer as correct and helpful if it resolves your issue. Happy Scripting
-Shantanu