Send email to business owner who owns multiple applications

JuniorDev82
Tera Contributor

Hi,

I need to send email notification to a group of business owners to certify data for business applications on yearly basis. 1 business owner may own multiple business apps, hence i need to make sure the email is send only once to every business owner even though they own multiple business apps. I was wondering if anyone has done this before in Flow designer? If so, how did you configure this?

 

Thanks

Junior Developer

1 ACCEPTED SOLUTION

Hi @JuniorDev82 ,

 

I had given a solution for sending single email to respective owner, you had not mentioned that you need to include list of apps as well. No worry.

 

you can do like below.

var appGr = new GlideRecord('business_application');
appGr.addActiveQuery();  
appGr.query();

var businessOwners = {};

while (appGr.next()) {
   var owner = appGr.business_owner;  // Replace with actual business owner field
   var appName = appGr.application_name;  // Replace with actual application name field

   if (!businessOwners[owner]) {
      businessOwners[owner] = [];
   }
   // Add the application name to the owner's list
   businessOwners[owner].push(appName);
}

// Send email notification to each business owner
for (var owner in businessOwners) {
   var appsList = businessOwners[owner].join(', ');  // Combine application names

   gs.eventQueue('business.app', null, owner, appsList);
}

Create one event based notification and content like below.

Dear ${recipient},

You are the owner of the following business applications:
${event.parm2}  // This will be replaced with the list of applications 

Please certify the data for these applications by [Due Date].

Best regards,
Your Team

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

View solution in original post

9 REPLIES 9

JuniorDev82
Tera Contributor

@MK-p 

 

Did you create event, notification and then a scheduled job and run the scrip provided by Runjay?

MK-p
Tera Contributor

Hi @JuniorDev82 ,

 

Yes, i have follow the runjay's steps mentioned above.

Hi @Runjay Patel @MK-p 

This script works if I just send the email to the business owner without listing out all applications that owns by him/her. I'm a bit lost when I have to also include the list of applications for every unique owner, I tried to iterate through each owner to get their applications and initialize a list to store applications name but ended up the emails are send repetitive due to the number of application they owned. Any idea how could i achieve this with sending only 1 email to unique owner and list of the applications in the same email? Thanks

Hi @JuniorDev82 ,

 

I had given a solution for sending single email to respective owner, you had not mentioned that you need to include list of apps as well. No worry.

 

you can do like below.

var appGr = new GlideRecord('business_application');
appGr.addActiveQuery();  
appGr.query();

var businessOwners = {};

while (appGr.next()) {
   var owner = appGr.business_owner;  // Replace with actual business owner field
   var appName = appGr.application_name;  // Replace with actual application name field

   if (!businessOwners[owner]) {
      businessOwners[owner] = [];
   }
   // Add the application name to the owner's list
   businessOwners[owner].push(appName);
}

// Send email notification to each business owner
for (var owner in businessOwners) {
   var appsList = businessOwners[owner].join(', ');  // Combine application names

   gs.eventQueue('business.app', null, owner, appsList);
}

Create one event based notification and content like below.

Dear ${recipient},

You are the owner of the following business applications:
${event.parm2}  // This will be replaced with the list of applications 

Please certify the data for these applications by [Due Date].

Best regards,
Your Team

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
LinkedIn: https://www.linkedin.com/in/runjay
YouTube: https://www.youtube.com/@RunjayP

-------------------------------------------------------------------------

Moin Kazi
Kilo Sage
Kilo Sage

Hi @JuniorDev82 ,

 

Follow the steps below to meet your requirements using Flow Designer:

 

  1. Create a Scheduled Trigger:

    • Create a new flow and set the trigger to a Scheduled Trigger to run yearly.
  2. Retrieve Business Owners:

    • Use the Get Records action to query the Business Application table (or the relevant table where business owners are defined).
    • Ensure you retrieve the unique business owners. You can use a Script to filter out duplicates.

    Example Script:

 

 

var uniqueOwners = {};
var gr = new GlideRecord('business_application'); // Replace with your table name
gr.query();
while (gr.next()) {
    var ownerEmail = gr.business_owner.email; // Adjust field names as necessary
    if (ownerEmail && !uniqueOwners[ownerEmail]) {
        uniqueOwners[ownerEmail] = true; // Store unique email
    }
}
return Object.keys(uniqueOwners);

 

 

 

 

      3 Send Email Notification:

  • After retrieving the unique business owner emails, use the Send Email action.
  • Set the To field to the list of unique email addresses retrieved in the previous step.            

     4 Email Content:

  • Craft the email subject and body to inform the business owners about the yearly certification process.

 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you found my response **helpful**, I’d appreciate it if you could take a moment to select **"Accept as Solution"** and **"Helpful"** Your support not only benefits me but also enriches the community.

 

Thank you!
Moin Kazi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~