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,...
Suggested Answer

Display form notification on lead based on value from the selected account?

(0) ShareShare
ReportReport
Posted on by 886

Hi,

I wan't to display a form notification (Warning) based on a value from the target record selected in a lookup field.

Ex. on leads i wan't to show a warning message in the top of the form if the field "Credit Hold / creditonhold" is set to yes for the selected account (Parent Account for lead / parentaccountid).

I found some guidance with javascript - hower this only covers if the field is on the same record. In this example it needs to load the value from the selected account. Maybe the guidance can be modified?

Dynamics 365 form level notification using JavaScript – Dynatecon Solutions

I have the same question (0)
  • Suggested answer
    MikeC282 Profile Picture
    2,175 on at

    You can do this in javascript. If you're after a value on a related field you should first use formContext to grab the account ID on the lead and then call a separate function using the web API to return the credit hold field from accounts. Remember though the web API is asynchronous so you'll need to factor that in when calling.

    It should look something like this:

    // Create namespace
    var Test = Test || {};

    // Add a function to the namespace
    Test.getCreditHoldAccount = function (accountId) {

        return new Promise((resolve, reject) => {
            var req = new XMLHttpRequest();
            req.open("GET", Xrm.Utility.getGlobalContext().getClientUrl() + `/api/data/v9.2/accounts(${accountId})?$select=creditonhold`, true);
            req.setRequestHeader("OData-MaxVersion", "4.0");
            req.setRequestHeader("OData-Version", "4.0");
            req.setRequestHeader("Accept", "application/json");
            req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
            req.onreadystatechange = function () {
                if (this.readyState === 4) {
                    req.onreadystatechange = null;
                    if (this.status === 200) {
                        var result = JSON.parse(this.response);
                        console.log(result);
                        // result of the Web API call
                        resolve(result["creditonhold"]);

                    } else {
                        reject('error message?')
                    }
                }
            };
            req.send();

        });

    }

    // Calling function
    Test.callingFunction = async function (executionContext) {

        let formContext = executionContext.getFormContext();
        // Get the full account lookup array
        let parentAccount = formContext.getAttribute("parentaccountid").getValue();
        if (parentAccount !== null && parentAccount !== undefined) {// Check if parent account lookup actually contains data
            // Get the account ID and slice away the brackets on either end
            let parentAccountId = parentAccount[0].id.slice(1, -1);
            // Get the CC details from the other function above that utilises the web API. Again cause it's asynchronous you should also await the result of the function.
            let cCDetails = await Test.getCreditHoldAccount(parentAccountId);
            if (cCDetails === true) { // Check if CC on hold is true
                // set form notification if it is on hold
                formContext.ui.setFormNotification('Credit on hold', 'WARNING', 'new_creditonhold');
            } else {
                // Clear form notification
                formContext.ui.clearFormNotification(new_creditonhold)


            }
           
        }
       
    }

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 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans