How to separate the items one by one using bullet point or number using script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:03 AM
Hi All,
I have written the schedule job for trigger the email notification to the catalog item owner.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:09 AM
do this
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('active=true^u_cat_item_owner.active=true^u_cat_item_ownerISNOTEMPTY');
//gr.addQuery('active=true^u_cat_item_owner.active=true^u_cat_item_ownerISNOTEMPTY^nameSTARTSWITHRetire a Standard Change Template');
gr.query();
// Create an object to store item names grouped by owner
var ownerItems = {};
while (gr.next()) {
var owner = gr.u_cat_item_owner;
//gs.log("ownerowner"+owner);
// Check if the owner is defined
if (owner) {
var itemName = gr.name.toString();
// Initialize an array for the owner if it doesn't exist
if (!ownerItems[owner]) {
//gs.log("ownerItems56"+ownerItems[owner]);
ownerItems[owner] = [];
}
// Push the item name into the owner's array
ownerItems[owner].push('<li>'+itemName+'</li>'); // while pushing use the <li> and </li> tags which adds bullet
//gs.log("ownerItems62"+ownerItems[owner]);
}
}
// Send notifications to owners with more than one item
for (var ownerKey in ownerItems) {
//gs.log("ownerItems[ownerKey].length" + ownerItems[ownerKey].length);
if (ownerItems[ownerKey].length >= 1) {
var itemNames = ownerItems[ownerKey]; // don't join here
//gs.log("itemNames"+itemNames);
//gs.log("ownerKey"+ownerKey);
gs.eventQueue('Catalog.item.owner.notification', gr, ownerKey, itemNames);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:27 AM - edited 09-20-2023 04:28 AM
I used the below code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:29 AM
share your email script?
are you using some extra logic in email script to print the data passed in event parm 2?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2023 04:34 AM