Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Unanswered

SetRequiredLevel not available in AddOnLoad context

Posted on by 325

Hi,

I am aiming to set a field's requirement level in an editable subgrid on load. As there's no 'OnLoad' event in an editable subgrid, I used AddOnLoad.

AddOnLoad is set on load of the Contact form. The function in the AddOnLoad is triggered when I open the editable grid's tab. Upon debugging it works, but I cannot find the control property's 'SetRequiredLevel'.

Here's my code:

        public SetMandatoryFields(context) {
            var formContext = context.getFormContext();
            var gridRows = formContext.getGrid().getRows();

            gridRows.forEach(
                function (row) {
                    var attributes = row.getData().getEntity().attributes;

                    attributes.forEach(
                        function (attr) {
                            if (attr.getName() == "new_severity") {
                                var ctrls = attr.controls;
                                ctrls.forEach(
                                    function (ctrl) {
                                        ctrl.setRequiredLevel("required");
                                    }
                                );
                            }
                        }
                    );
                }
            );
        }

It is simple if it's on change of a field in the editable grid but not On Load of the grid.

Thanks!

  • Manish Jain Profile Picture
    Manish Jain 50 on at
    RE: SetRequiredLevel not available in AddOnLoad context

    Hi PDCM,

    Try getting the entity object using following code :

    var entityObject = formContext.data.entity;

    then get the field

    var field = entityObject.attributes.getByName(fieldName);

    //field.getRequiredLevel() //

    field.setRequiredLevel("required/none");

    Thanks

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans