Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Subscription management Access

Rafael Batistot
Kilo Patron

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

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.
2 REPLIES 2

pratikjagtap
Giga Guru
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

 

If you found this response helpful, please mark it as Helpful. If it fully answered your question, consider marking it as Correct. Doing so helps other users find accurate and useful information more easily.