Trigger a email to the catalog item owner when job runs

vinuth v
Tera Expert

Hi All,

 

I need to trigger a email notification to the catalog item owner when the schedule job runs, for this I have created the event registry, Notification and email script. It's working as expected but facing one issue like body of the email Hi contains the static person(one specific name is displaying for all the email body) in all the email notification but I need to send the email to catalog item owner addressing like Hi {catalog item owner name need to display here}

 

 

Email body contains:

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.

 

Schedule Job,

If the catalog owner has owning multiple catalog item then need to send single email the owner, this script is working fine

var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active=true^u_cat_item_owner.active=true^u_cat_item_ownerISNOTEMPTY');
gr.query();
// Create an object to store item names grouped by owner
var ownerItems = {};
while (gr.next()) {
var owner = gr.u_cat_item_owner;
// Check if the owner is defined
if (owner)
{var itemName = gr.name.toString();
if (!ownerItems[owner]) {
            ownerItems[owner] = [];
        }
ownerItems[owner].push(itemName);
    }
}
// Send notifications to owners with more than one item
for (var ownerKey in ownerItems) {
    if (ownerItems[ownerKey].length > 1) {
        var itemNames = ownerItems[ownerKey].join(', '); 
        gs.eventQueue('Catalog.item.owner.notification', gr, ownerKey, itemNames);
    }
}
 
Notification 
vinuthv_0-1694172080428.png

 

vinuthv_1-1694172109137.png

 

vinuthv_2-1694172224577.png

 

Here email will trigger to specific catalog item owner but 

Body of the email like Hi part contains the static person for all the email notifications

like below

vinuthv_3-1694172434553.png

 

 

Email Script:

vinuthv_4-1694172975441.png

 

 

 
Please any one provide me the input,
 
Thanks in advance,
Vinuth

 

6 REPLIES 6

Hi @Rutuja K 

 

Are you getting length as 3 from the log statement ? I tried simulating your issue on my PDI and I am able to get individual links for  all the 3 catalog items with sys_id. I doubt that your array is not being populated properly from the event so please check the output for both the log statements.

 

You need to add array.toString() to your log statement to check the items of the array.

 

Thanks & Regards

Amit Verma


Please mark this response as correct and helpful if it assisted you with your question.

Hi Amit,

 

Thank you for response. 

In logs I can see links for all 3 catalog items. Problem is I am not getting it in Notifications.

For 2 catalog items, getting it like instancelink.com/portal?id=sc_cat_item&sys_id=