Auto populating the users in software license table
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 11:34 PM
Hi Guys,
I have a task related to granting software access to users. If access is available, users should be added to the software license/entitlement, and their rights to the software should be reduced accordingly. I am currently writing a background script to accomplish this. While the script is functioning correctly, the user is not being added to the license table. Could someone help me resolve this issue? I'm attaching the code and a screenshot for your reference.
Reference code:
var user = '4ee3c528c3cc26106c1efbfdd40131b7';
var software = 'b758c153c3d426106c1efbfdd40131f8';
var abs = new GlideRecord('alm_license');
abs.addQuery('model', software);
abs.addQuery('rights', '>', 0);
//abs.addQuery('assigned_to', user);
abs.query();
if (abs.next()) {
var abc = new GlideRecord('alm_entitlement');
abc.addQuery('licensed_by', software);
abc.query();
var actualRows = abc.getRowCount();
if (actualRows > abs.rights) {
//abc.addErrorMessage(abc.getMessage('Cannot allocate more licenses than rights'));
gs.print('Row count is:' + abc);
//current.setAbortAction(true);
}
abc.initialize();
abc.assigned_to = user;
abc.licensed_by = software;
abc.insert();
abs.rights = parseInt(abs.rights) - 1;
abs.update();
gs.print('User' + user + 'has added');
} else {
gs.print('no user added');
}
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2025 07:10 AM
Did you try to use the Flow Designer for this?
*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************