Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Prevent required field error message coming up before save

Posted on by 3,079

I have some situations where I have filtered lookups (i.e. lookup B has its values filtered based on the value of an earlier lookup A).  However, OOTB, if you change A, B keeps its value, which is likely no longer a valid combination with A.

So I added javascript onChange of A to clear out B - basically reset it, so the user now has to pick a valid option from B.  This works fine, except that - since B is a required field - the user sees the red circled "X" along with "You must provide a value" on B as soon as they change A.  I don't like the user experience of giving them an error before they've had a chance to do the thing that would prevent the error.  I'd like to suppress this warning until it's relevant, which is when they're trying to save.  Any idea why it comes up before save, and how to suppress/clear it until then?

*This post is locked for comments

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Prevent required field error message coming up before save

    *facepalm*  Makes sense.  Threw in a check to see if the field is required or not before setting/unsetting, since this is a generic function I'm using in a few places, but of course that works.  I was focused on clearing the error message itself somehow, rather than just sidestepping.  Thanks!

  • Verified answer
    am462 Profile Picture
    am462 110 on at
    RE: Prevent required field error message coming up before save

    One option you have is to add Xrm.Page.getAttribute("attributeName").setRequiredLevel("none"); at the beginning of your onChange method and then Xrm.Page.getAttribute("attributeName").setRequiredLevel("required"); at the end of it. It seems to not show the red cross until you actually focus on the field and then click/tab away.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Prevent required field error message coming up before save

    You could set to "recommended" which would give the little '+' sign next to the field (instead of the asterisk). Not sure if that is exactly what you want, but may be as close as you can get without manipulating the DOM.

  • awalters Profile Picture
    awalters 3,079 on at
    RE: Prevent required field error message coming up before save

    Thanks for the idea!  My concern, though, is that it then removes the visual cue for the user that they need to enter that field, which could also cause confusion.  Unless I also in JS just add in the asterisk manually, but I'm not sure if that's possible in a supported way (cause the only way I can think of requires DOM manipulation.  Not a big JS expert, though, so definitely could be missing an option).

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Prevent required field error message coming up before save

    Hi Allison,

       What about using javascript to turn off the field requirement for lookup B when OnChange of lookup A happens? You could then turn it back on with javascript in the OnSave event, and it would then flag them at that point if they didn't select something for lookup B.

    Hope that helps.

    John

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