web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Mahendar Pal Profile Picture
    45,095 on at

    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");
            }
            }

  • JakeD2L Profile Picture
    2,355 on at

    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!

  • JakeD2L Profile Picture
    2,355 on at

    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

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans