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

Forum Post: Change the Filter On option on Opportunity Associated View for Account form

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.

// 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);


                    // result of the Web API call


                } else {

                    reject(‘error message?’)







// 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







Source link

Leave a reply

Please enter your comment!
Please enter your name here