The CreatorCon Call for Content is officially open! Get started here.

Need count of licenses under software model form to be displayed in catalog form text field

ServiceNow10sun
Giga Guru

Hi All,

 

In the table alm_license  there is  related list 'license entitlements' . For each software license there is catalog form so the requirement is  user needs the number of count of 'license entitlements' to be displayed in one text field available in catalog form of each software catalog example "Variable name is lic count (type is multi line text filed).

 

I have achieved this for one catalog using script include and called the class into a on load catalog client script  and it is working , however my issue here is  I have total of more than 100 catalog  for each Software  , so do i need to create more than 100 script includes + Catalog client script ? or in one script include i need to write 100 classes and call in one catalog client script?

 

Any suggestions or help much appreciated.

 

sunita10_0-1691492981765.png

 

 

 

6 REPLIES 6

I belive licSysId contains the sys_id as per its name then script is straight fwd on variable set.

 

var populatelicensecount1 = Class.create();

populatelicensecount1.prototype = Object.extendsObject(AbstractAjaxProcessor, {

getLicensecount: function(licSysId) {

        gs.info("Received licSysId: " + licSysId); // Add this line for debugging

 

        var lic = new GlideRecord('alm_license');

        lic.addQuery('sys_id',licSysId);

        lic.query();

 

        var rowCount = lic.getRowCount();

        gs.info("Row count: " + rowCount); // Add this line for debugging

 

        return rowCount;

    },

 

    type: 'populatelicensecount1'

});

 

you just have to call the script include and its function with paramter that contains the sys_id for alm_license table (may be from other variable).

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi,

 

am using this catalog client script 

function onLoad() {
    // var licSysId = g_form.getValue('software_model');
    // alert(licSysId);
 
    var ajax = new GlideAjax('populatelicensecount1');
    ajax.addParam('sysparm_name', 'getLicensecount');
    // ajax.addParam('sysparm_licSysId', licSysId);
    ajax.getXML(handleResponse);
g_form.setReadOnly('show_license_count',true);
}
 
function handleResponse(response) {
    var answer = response.responseXML.documentElement.getAttribute('answer'); // Corrected line
    g_form.setValue('show_license_count', 'Number of license count: ' + answer);
    alert(answer);
}
 
so any changes i have to do for this please suggest 
thanks