Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Making an entities field required based on another entities field

Posted on by 230

Hi,

I am wondering if it is possible to make a field on a contact record required if a field on the related account record equals a particular option? My suspicion is no based on playing around with the business rules, so I am also wondering what the best alternative might be?

Thanks,

Rob

*This post is locked for comments

  • Suggested answer
    Pawar Pravin  Profile Picture
    Pawar Pravin 5,227 on at
    RE: Making an entities field required based on another entities field

    Hi,

    Agree with Ben, you need to retrieve other entity record so that you can check condition and moreover you need to use following syntax:

    Xrm.Page.getAttribute("logicalnameoffield") ? Xrm.Page.getAttribute("logicalnameoffield").setRequiredLevel("required") : false;  

    Hope this help you... !

    Regards,

    Pravin

  • Suggested answer
    Ben Thompson Profile Picture
    Ben Thompson 6,350 on at
    RE: Making an entities field required based on another entities field

    The easiest way would be a piece of Javascript loaded when the page loaded and when the value of the related account record was changed.

    Something like this should do it

    function makeFieldRequired()

    {
    // set field as none mandatory before starting off as its easier than doing it later in multiple places.

    Xrm.Page.getAttribute("field to make mandatory").setRequiredLevel("none");

    // get the accountId from the form
    var accountId="";
    if (Xrm.Page.data.entity.attributes.get("accountId").getValue() != null) {
    accountId = Xrm.Page.data.entity.attributes.get("fieldname").getValue()[0].id;
    }

    if (accountId!= ""){
    // if it's found we can now query the account record for the field we care about

    Xrm.WebApi.retrieveRecord("account", accountId, "?$select=name,fieldname").then(function success(result) {
    // Perform operations on record retrieval
    if (result.fieldname== "expectedvalue") {
    Xrm.Page.getAttribute("field to make mandatory").setRequiredLevel("required");
    }
    ,function error(result){console.log("something went wrong: "+error.message);});
    }


    }

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,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans