Subscription management Access

Rafael Batistot
Tera Sage

Hi Team, 

 

How can i access the Subscription management via Script? 

I want to be able to create a Business Rule with a warning msg to user, case there is no Subscription available

 

Thank's in advanced

2 REPLIES 2

pratikjagtap
Giga Guru

Hi @Rafael Batistot ,

 

Try below BR

 

 

(function executeRule(current, gS, gUser, gSUtil) {

// Define the subscription you're checking for
var productName = "ITSM Enterprise"; // example
var licenseType = "requester"; // adjust as needed

// Query the subscription record
var subGR = new GlideRecord('sn_subscriptions.subscription');
subGR.addQuery('product_name', productName);
subGR.addQuery('license_type', licenseType);
subGR.query();

if (subGR.next()) {
var total = subGR.getValue('quantity');
var used = subGR.getValue('used');

if (parseInt(used) >= parseInt(total)) {
gs.addInfoMessage("Warning: No available subscriptions for " + productName + ". Please contact admin.");
}
} else {
gs.addInfoMessage("Warning: Subscription info not found for " + productName + ".");
}

})(current, gs, gs.getUser(), gs.getSession());

 

If my response helped, please hit the 👍Thumb Icon and accept the solution so that it benefits future readers.

 

Regards,
Pratik

Hi @pratikjagtap, it's doesn't work 

RafaelBatistot_0-1749743791786.png