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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Dynamics 365 Javascript - wait to load all controls on the form

(1) ShareShare
ReportReport
Posted on by 30

Hi,

I have a function in JavaScript which actually sets NULL value in Email_Allowed field if there is no value in "Email" field.

So, the logic mentioned below is working fine in unmanaged solution, but it is not setting null value in managed solution.

function handleAllowedFields(dataField, allowedField) {

    return function () {
        if (dataField == null || allowedField == null) {
            return;
        }

        if (dataField.getValue() == null) {
            allowedField.setValue(null);
            allowedField.setRequiredLevel("none");
            allowedField.controls.forEach(function (c) {
                c.setDisabled(true);
            });
        } else {
            // If dataField is having a value, then contact preference fields
            // can have an value as Allow OR DoNotAllow ONLY.
            allowedField.controls.forEach(function (c) {
                c.setDisabled(false);
            });
            allowedField.setRequiredLevel("required");
        }
    }
}

When I debugged it in managed solution, I found that it is working in debug mode but NOT in regular mode. To me, it looks like it is not able to find the control in regular mode.

Help please.

I have the same question (0)
  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    First of all, how did you get the "dataField" and "allowedField" before entering this function? I suggest to use "formcontext.getAttribute" instead of "Xrm.page".

    If you already used formcontext and still can't find the control, you could add a setTimeOut to keep running this function until all the controls have been loaded.

    Also you need to add the settimeout function before you get the fields.

    setTimeout(function(){//get field by formcontext...}, 3000);

    In normal, running js functions in managed or unmanaged solutions should not have differences. So you could also check if there is any other customizations which may affect your js code.

    Hope it helps.

    Best Regards,

    Leo

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans