The CreatorCon Call for Content is officially open! Get started here.

Need to send a notification to the Catalog owner

vinuth v
Tera Expert

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

19 REPLIES 19

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

@vinuth v 

 

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

 

Mohith Devatte
Tera Sage
Tera Sage

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

 

Hi @Mohith Devatte 

 

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 :

 

(function runMailScript(current, template, email, email_action, event) {
 
          // Add your code here
var cNames = event.parm2.split(',');
    template.print(cNames);
 
})(current, template, email, email_action, event);
 
Used in the notification :

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

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 

var cNames = event.parm2;
    template.print(cNames);
 
 
Also please let me know if the notification is getting triggered or not ? 
if its triggered are the catalog item names printed or is it coming empty?