Skip to main content

Notifications

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
    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
    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
    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
    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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
dkrishna Profile Picture

dkrishna 6

Featured topics

Product updates

Dynamics 365 release plans