web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Dynamically populating Quote Email with Quote Data

(1) ShareShare
ReportReport
Posted on by 3,313
Hi All
When creating an email from the Quote, is it possible to retrieve quote data such as contact as the "to" email and other details from custom fields: The standard use custoemr as the to email but we want a named contact on the Quote for example below:.  I have looked at Javascript and workflows but dont know how to link back to Quote. We dont want the email to be sent before user checks
I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at
    Hi,
     
    Yes, you can write script on load of email form where you can read quote from regarding lookup and based on the the quote you can use Web API retrieve method to get quote details and set it on the email. 

    Below are some of the link that will help you:


     
    Let us know if you are facing any issue
     
    Thanks,
    Mahender
    Blog: https://himbap.com/blog
    Please mark as Verified if this answered your question!
  • Verified answer
    Amit Katariya007 Profile Picture
    10,409 Moderator on at
    To retrieve quote data (e.g., contact email) when creating an email from a quote in Dynamics 365, you can use JavaScript to pre-fill fields in the email form based on the data from the related quote. Here's a JavaScript code to achieve this:
     
    Steps to Implement
     
    1. Identify the Fields:
    Ensure the quote has a field for the contact (e.g., contact or contactid) and custom fields with the required data.
     
    Identify the relationship between the quote and the email (Regarding field typically links them).
     
    2. JavaScript to Retrieve Data:
    Use a JavaScript web resource to fetch data from the quote and populate the email form
     
    3. Trigger the Script:
    Attach the JavaScript to the OnLoad event of the Email form or a custom button in the ribbon.
     
    JavaScript Code Example
     
    function populateEmailFromQuote(executionContext) {
        var formContext = executionContext.getFormContext();
        var regardingId = formContext.getAttribute("regardingobjectid").getValue();
     
        // Check if the regarding object is a quote
        if (regardingId && regardingId[0].entityType === "quote") {
            var quoteId = regardingId[0].id.replace(/[{}]/g, ""); // Remove curly braces
     
            // Retrieve Quote Data via Web API
            Xrm.WebApi.retrieveRecord("quote", quoteId, "?$select=contactid,_customfield1,_customfield2").then(
                function (quote) {
                    // Set the 'To' email address with the contact email
                    if (quote["_contactid_value"]) {
                        Xrm.WebApi.retrieveRecord("contact", quote["_contactid_value"], "?$select=emailaddress1").then(
                            function (contact) {
                                if (contact.emailaddress1) {
                                    var to = [{
                                        entityType: "contact",
                                        id: contact.contactid,
                                        name: contact.fullname
                                    }];
                                    formContext.getAttribute("to").setValue(to);
                                }
                            },
                            function (error) {
                                console.error("Error retrieving contact: " + error.message);
                            }
                        );
                    }
     
                    // Set custom field values in the email body or subject
                    var emailBody = `Custom Field 1: ${quote._customfield1}\nCustom Field 2: ${quote._customfield2}`;
                    formContext.getAttribute("description").setValue(emailBody);
     
                },
                function (error) {
                    console.error("Error retrieving quote: " + error.message);
                }
            );
        }
    }
     
    Explanation of the Code
     
    1. Retrieve Quote Data:
    The retrieveRecord method fetches the quote's contact and custom field values.
     
     
    2. Retrieve Contact Email:
    Once the contactid is retrieved from the quote, the script queries the contact to fetch its email address (emailaddress1).
     
     
    3. Set the Email Fields:
     
    The "To" field is set using the contact entity.
     
    The email body or subject is updated with values from the quote's custom fields.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 66 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 45

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans