email notifications

tGhadage
Tera Contributor

I am trying to pull through details of company table in the notifications which is on the asset entry table.

how shall I do it ? 

 

never worked on the email script please guide .

2 REPLIES 2

SN_Learn
Kilo Patron
Kilo Patron

Hi @tGhadage  ,

 

Please check the below exercise and modify it according to your requirement:

Exercise: Notification Email Scripts 

 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Aniket Chavan
Tera Sage
Tera Sage

Hello @tGhadage  ,

Could you please provide more details on your requirements? Specifically, what information from the Company table do you need to include in the notification, and how would you like it to appear? This will help us guide you more effectively on how to use an email script to achieve your goal.

To give you an idea of how an email script might look, here’s a sample script for fetching and displaying Company details associated with an Asset. This example assumes that you have a reference field linking the Asset to the Company table:

(function runMailScript(current, template, email, email_action, event) {
    // Create a GlideRecord to fetch Company details associated with the Asset
    var companyGR = new GlideRecord('core_company'); // core_company is the table name for Company records
    companyGR.get(current.company); // Assumes 'company' is a reference field on the Asset table
    
    // Add details from the Company record to the email
    if (companyGR.isValidRecord()) {
        template.print("Company Name: " + companyGR.name + "<br>");
        template.print("Company Location: " + companyGR.location + "<br>");
        template.print("Company Phone: " + companyGR.phone + "<br>");
        // Add any other details you need from the companyGR fields
    } else {
        template.print("Company details not found.");
    }
})(current, template, email, email_action, event);

 

Add the email script to your notification by using below format:

${mail_script:CompanyDetailsForAsset}

 

Please Mark Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.


Regards,
Aniket