Checking the Roles licenses
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2023 08:48 PM
Hi Experts,
How do check roles licenses in ServiceNow and subscript within the limit or not?
Thanks
Thiru
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2023 09:00 PM
HI @thirumala goud ,
I trust you are doing great.
To check roles licenses in ServiceNow and determine if the subscription is within the limit, you can utilize the ServiceNow API and specifically query the "sys_user_has_role" table. Here's an example of a technical solution to achieve this:
- Create a new Script Include in ServiceNow.
var RoleUtils = Class.create();
RoleUtils.prototype = {
initialize: function() {},
// Function to check if the user's role license count is within the limit
isLicenseWithinLimit: function(userId, roleName, licenseLimit) {
var gr = new GlideRecord('sys_user_has_role');
gr.addQuery('user', userId);
gr.addQuery('role.name', roleName);
gr.query();
var roleCount = gr.getRowCount();
return roleCount <= licenseLimit;
},
type: 'RoleUtils'
};
- In your client-side script or server-side script, you can use the RoleUtils script include to check the roles licenses for a user:
var userId = 'user_sys_id'; // Replace with the actual user's sys_id
var roleName = 'role_name'; // Replace with the actual role name
var licenseLimit = 5; // Replace with the actual license limit
var roleUtils = new RoleUtils();
var isWithinLimit = roleUtils.isLicenseWithinLimit(userId, roleName, licenseLimit);
if (isWithinLimit) {
gs.info('The user is within the license limit for the role.');
} else {
gs.info('The user has exceeded the license limit for the role.');
}
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi