- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 07:45 AM
Hello!
I had to repost not to make you confused. I have a problem that I need to refigure completely.
The scheduled job I'm working on is based on alm_hardware. Keep in mind that a "manager" (Manager) can have several managed_by (responsible persons) under him/her.
I want to trigger so that only one per "manager" mail is sent, containing all the "managed_by"s under him/her (so managed_by.manager).
This is my current scheduled jobs script:
var gr = new GlideRecord('alm_hardware');
gr.addEncodedQuery('managed_by.active=false^install_status=1');
gr.query();
while (gr.next()) {
var manager = gr.managed_by.manager;
if (manager && manager.active) {
var eventParms = gr.display_name + ';' + gr.managed_by.name;
gs.eventQueue('vgr_inactive_hardware_manager', gr, eventParms, manager.sys_id);
}
}
I want to use the event called 'vgr_inactive_hardware_manager'.
The mail looks like this, with the marking part on repeat per managed_by under the manager:
All good! 🙂
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 08:54 AM
Hi @ronro2
Please find the below script which will trigger one event (and subsequent notification) per "manager" containing all the Assets by the "managed_by" field.
Example: If there are 100 assets managed equally between 5 managers - 5 emails will be sent to each manager containing a list of the 20 assets assigned to them
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
var assetsByManager = 0; var allAssetsInScope = 0; var gaAssets = new GlideAggregate('alm_hardware'); gaAssets.addEncodedQuery('managed_by!=NULL^install_status=1'); //Adjust the conditions as you see fit but you cant send emails to inactive users so is your condition correct? gaAssets.groupBy('managed_by') gaAssets.query(); while (gaAssets.next()) { var arr = []; var grAssets = new GlideRecord('alm_hardware'); grAssets.addQuery('managed_by', gaAssets.managed_by); grAssets.addQuery('install_status=1'); grAssets.query() while (grAssets.next()) { var details = grAssets.display_name + ' - ' + grAssets.managed_by.name; arr.push(details + ''); allAssetsInScope++; //gs.print('Testing details: ' + details); } gs.print('** FINAL **: ' + arr.toString()); assetsByManager++; gs.eventQueue('vgr_inactive_hardware_manager', gaAssets, eventParms, gaAssets.managed_by); } gs.print('assetsByManager: ' + assetsByManager); gs.print('allAssetsInScope: ' + allAssetsInScope);
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 08:54 AM
Hi @ronro2
Please find the below script which will trigger one event (and subsequent notification) per "manager" containing all the Assets by the "managed_by" field.
Example: If there are 100 assets managed equally between 5 managers - 5 emails will be sent to each manager containing a list of the 20 assets assigned to them
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie
var assetsByManager = 0; var allAssetsInScope = 0; var gaAssets = new GlideAggregate('alm_hardware'); gaAssets.addEncodedQuery('managed_by!=NULL^install_status=1'); //Adjust the conditions as you see fit but you cant send emails to inactive users so is your condition correct? gaAssets.groupBy('managed_by') gaAssets.query(); while (gaAssets.next()) { var arr = []; var grAssets = new GlideRecord('alm_hardware'); grAssets.addQuery('managed_by', gaAssets.managed_by); grAssets.addQuery('install_status=1'); grAssets.query() while (grAssets.next()) { var details = grAssets.display_name + ' - ' + grAssets.managed_by.name; arr.push(details + ''); allAssetsInScope++; //gs.print('Testing details: ' + details); } gs.print('** FINAL **: ' + arr.toString()); assetsByManager++; gs.eventQueue('vgr_inactive_hardware_manager', gaAssets, eventParms, gaAssets.managed_by); } gs.print('assetsByManager: ' + assetsByManager); gs.print('allAssetsInScope: ' + allAssetsInScope);
To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.
Thanks, Robbie