Population of install_count in software discovery model --reg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 06:12 AM
Hello Guys,
how the field install_count in software discovery model is populated, I just try to refer many jobs and scripts but, I cannot find one , I also think that it is not an reference field.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-17-2024 10:23 PM
Hello @KesavanM,
Please refer to the link below:
https://www.servicenow.com/community/sam-forum/install-count-for-software-models/m-p/2824430
If it is helpful, please mark it as helpful and accept the correct solution. In future, it might be helpful for someone to refer to this solution.
Thanks & Regards,
Abbas Shaik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 09:42 AM
Hi @KesavanM it's done by the method 'updateInstallCount' in the protected script include "SamDiscoveryModelNormalization" which is called from the scheduled job "SAM - Normalize discovery models using content library rules" as so.
If you found this useful, please mark my answer as helpful.
Scheduled Job:
sampRunNormalization();
function sampRunNormalization() {
new SamDiscoveryModelNormalization().process();
// Update install count on Discovery models
var script = 'new global.SamDiscoveryModelNormalization().updateInstallCount();';
GlideRunScriptJob.scheduleScript(script);
}
Method in script:
updateInstallCount: function (lastDiscoveryModel) {
var jobLogUtil = new global.AssetJobLogUtil();
jobLogUtil.startJobLog("Update install count on discovery models");
var C_TIMEOUT = 900000;
var stopWatch = new GlideStopWatch();
var grDM = new GlideRecord("cmdb_sam_sw_discovery_model");
grDM.orderBy("sys_id");
if (!gs.nil(lastDiscoveryModel)) {
grDM.addQuery("sys_id", ">", lastDiscoveryModel);
}
grDM.query();
var DMsProcessed = 0;
while (grDM.next()) {
var installsGa = new GlideAggregate("cmdb_sam_sw_install");
installsGa.addQuery("discovery_model", grDM.getUniqueValue());
installsGa.addAggregate("COUNT");
installsGa.query();
installsGa.next();
grDM.setValue("install_count", installsGa.getAggregate("COUNT"));
grDM.setWorkflow(false);
grDM.update();
DMsProcessed += 1;
if (stopWatch.getTime() >= C_TIMEOUT && grDM.hasNext()) {
var script = "new global.SamDiscoveryModelNormalization().updateInstallCount('" + grDM.getUniqueValue() + "');";
GlideRunScriptJob.scheduleScript(script);
break;
}
}
jobLogUtil.stopJobLog(jobLogUtil.COMPLETED_STATUS, "Discovery models processed - " + DMsProcessed)
}