Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript Q - Required fields based on two other fields

(0) ShareShare
ReportReport
Posted on by 2,355

I had a question about some javascript setting a field to required when one option was chosen. I have a similar situation where I need to set the required of one field if Field A = 1 and Field B = 2.

Basically I thought it would be an "If" and "and" function but I'm not sure how to write that.

community.dynamics.com/.../107277.aspx

Thanks!

*This post is locked for comments

  • JakeD2L Profile Picture
    JakeD2L 2,355 on at
    RE: JavaScript Q - Required fields based on two other fields

    Also for this, what field would I add the function as a Event Handler in or do I add it in both Fields?

  • JakeD2L Profile Picture
    JakeD2L 2,355 on at
    RE: JavaScript Q - Required fields based on two other fields

    edit: The tab shows then Type A and Type B are shown and the field on that tab shows when User 4 is chosen.

    So if User 3 is chosen and Type D is chosen the field should not be required. It should only be required when:

    - Field A = Type A, Field B = User 4

    OR

    - Field A = Type B, Field B = User 4

  • JakeD2L Profile Picture
    JakeD2L 2,355 on at
    RE: JavaScript Q - Required fields based on two other fields

    Thanks Mahendar.

    I think this might be more complicated than I originally thought. For Field A, there are 4 values (Type A - Type D) and for Field B, there are also 4 values (User 1 - User 4). The field I want to change the requirement level on is in another tab. The reason I want to change the requirement level is because the tab the field is on does not always show and if its required then it wont save in some situations.

    The tab shows then User 1 and User 2 are shown and the field on that tab shows when Type D is chosen.

    Any thoughts?

    Thanks!

  • Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: JavaScript Q - Required fields based on two other fields

    Hello,

    you need to check like below, change field names accordinly

    var valueA= Xrm.Page.getAttribute("A_FieldName").getText();
    var valueB=Xrm.Page.getAttribute("B_FieldName").getText();
        if (valueA != null && valueB!=null) {
            if (valueA ==1 && valueB==2) {
                Xrm.Page.getAttribute("FieleName").setRequiredLevel("required");
            } else {
                Xrm.Page.getAttribute("FieleName").setRequiredLevel("none");
            }
            }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,489 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,305 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans