Need to send a notification to the Catalog owner
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:14 AM - edited 08-31-2023 05:32 AM
Hi All,
I need to trigger the email notification to the catalog item owner, Currently I have written the code to trigger email notification like this and I am using the schedule job to trigger the notification.
var gr = new GlideRecord('sc_cat_item');
gr.addEncodedQuery('active=true^u_cat_item_owner.active=true^u_cat_item_ownerISNOTEMPTY');
gr.query();
while (gr.next()) {
var owner = gr.u_cat_item_owner;
if (owner) {
gs.eventQueue('Catalog.item.owner.notification', gr, gr.u_cat_item_owner, '');
}
}
It's working fine,
Current notification body,
Hi Scott Bennett,
You have received this email because you are the owner of the catalog item "Report an issue with Checkpoint Marketing".
Please review the form for any of the below points.
But if the catalog item owner having multiple catalog items then I need to send the single email notification to the catalog owner rather then multiple notification.
Thanks in advance
Vinuth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:36 AM - edited 08-31-2023 05:38 AM
Hi @Karthiga S
For example if the owner is Lynn if she is the owner of the 10 catalog item form, then I need to send single email notification to Lynn, and email body contains 10 catalog item forms with separate with the commas (,)
Thanks,
Vinuth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:49 AM - edited 08-31-2023 05:50 AM
Use below code
var item = new GlideAggregate('sc_cat_item');
item.addEncodedQuery('active=true^u_cat_item_owner.active=true^u_cat_item_ownerISNOTEMPTY');
item.groupBy("u_cat_item_owner");//pass backend name of catalog item owner
item.query();
while (item.next()) {
var owner = gr.u_cat_item_owner;
if (owner) {
gs.eventQueue('Catalog.item.owner.notification', gr, gr.u_cat_item_owner, '');
}
If your schedule is running daily then owner will receive notification daily ,just to avoid it ,add condition add condition in your scheduled job
If my answer solved your issue, please mark my answer as ✅Correct & 👍Helpful based on the Impact
Thanks,
Manjusha Bangale
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:39 AM
Hello @vinuth v you can push all the catalog item names into an array and modify the current body and trigger event only once like below
i declared an array and pushed all the catalog item names into an array and then sent the array of catalog items names as param2
var arr=[];
var owner ='';
var gr = new GlideRecord('sc_cat_item');
gr.query();
while (gr.next()) {
arr.push(gr.name.toString());
owner = gr.owner;
}
if (owner) {
gs.eventQueue('your.email.notification', gr, gr.owner, arr.toString());
}
Create a email script to catch the parm2 and use the email script in notification to print catalog item names
your email scirpt can be like below
var cNames = event.parm2.split(',');
template.print(cNames);
In your notification body access your email script like below to print names .
Syntax:{mail_script:your_email_Script_name}
Hi Scott Bennett,
You have received this email because you are the owner of the catalog items {mail_script:your_email_Script_name}.
Please review the form for any of the below points.
Hope this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 03:44 AM - edited 09-01-2023 03:45 AM
I tried like this, but it's not working
Used in the schedule job
var arr=[];
var owner ='';
var gr = new GlideRecord('sc_cat_item');
//gr.addEncodedQuery('active=true^u_cat_item_owner.active=true^u_cat_item_ownerISNOTEMPTY');
gr.query();
while (gr.next()) {
arr.push(gr.name.toString());
owner = gr.u_cat_item_owner;
}
if (owner) {
gs.eventQueue('Catalog.item.owner.notification', gr, gr.u_cat_item_owner, arr.toString());
}
Email script :
Hi ${u_cat_item_owner},
You have received this email because you are the owner of the catalog item {mail_script:Catalog item owner email script}.
Please review the form for any of the below points.
Thanks,
Vinuth
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2023 03:52 AM
Hello @vinuth v make sure you email script name does not have space .better replace your name to below and use it in notification
Catalog_item_owner_email_script
Also replace your email script to below