Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

how to change fields value based on other fields

Posted on by Microsoft Employee

hello, i have a question.

i have 3 fields that has the same data type = two options.

A = yes / no

B = yes / no

C = yes / no

if i change one of them into "yes" option, the other fields will be automatically "no"

it must be only 1 yes within this 3 fields.

how to change it? 

  • gdas Profile Picture
    gdas 50,085 on at
    RE: how to change fields value based on other fields

    Have you tried to do my second options creating three business rules (no code approach )?

    If you have not tried then I would suggest try once my second answer, I did my local environment its working . Please don't forget to verify my second answer as this is better approach instead of JavaScript rules , please note  verifying answer will helps other people to choose right and best answer from community forum.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to change fields value based on other fields

    i've tried this one too, and it's work. thankyou so much! :)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: how to change fields value based on other fields

    i've tried this and it's work :D

    Thankyou! :)

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: how to change fields value based on other fields

    I found in my fast answer there is a discrepancy with one business rules , in that case you need to select All NO value and then you have to choose one YES. Its working but you need to click on twice  if there is already a YES value.

    To avoid this you need to create similar logic three different business rules like below  -

    First Business Rules - 

    =================================

    pastedimage1578478320897v1.png

    IF

    Field A equals "Yes"

    THEN
    Set FiedlB to "No"
    Set FieldC to "No"
    Second Business Rule 
    ====================
    IF

    FieldB equals "Yes"

    THEN
    Set FiedlA to "No"
    Set FieldC to "No"
    Third Business Rule
    ===================
    IF

    FieldC equals "Yes"

    THEN
    Set FiedlA to "No"
    Set FieldB to "No"
     
    Doing above is working as expected as per your requirement.
  • Verified answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: how to change fields value based on other fields

    Hi partner,

    You could use JS code to do this.

    1.Add this function on the "onchange" event of fieldA.

    function checkValueA(executionContext){
        var formContext=executionContext.getFormContext();
        var valueA=formContext.getAttribute("fieldA").getValue();
        var fieldB=formContext.getAttribute("fieldB");
        var fieldC=formContext.getAttribute("fieldC");
        if(valueA==true){
            fieldB.setValue(false);
            fieldC.setValue(false);
        }
    }

    2.Add this function on the "onchange" event of fieldB.

    function checkValueB(executionContext){
        var formContext=executionContext.getFormContext();
        var valueB=formContext.getAttribute("fieldB").getValue();
        var fieldA=formContext.getAttribute("fieldA");
        var fieldC=formContext.getAttribute("fieldC");
        if(valueB==true){
            fieldA.setValue(false);
            fieldC.setValue(false);
        }
    }

    3.Add this function on the "onchange" event of fieldC.

    function checkValueC(executionContext){
        var formContext=executionContext.getFormContext();
        var valueC=formContext.getAttribute("fieldC").getValue();
        var fieldB=formContext.getAttribute("fieldB");
        var fieldA=formContext.getAttribute("fieldA");
        if(valueC==true){
            fieldB.setValue(false);
            fieldA.setValue(false);
        }
    }

    Hope it helps.

    Best Regards,

    Leo

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: how to change fields value based on other fields

    Try to do with Business Rules.

    pastedimage1578476380190v1.png

    IF
    Field A equals "Yes"
    THEN
    Set FiedlB to "No"
    Set FieldC to "No"
    ELSE IF
    FiedlB equals "Yes"
    THEN
    Set Field A to "No"
    Set FieldC to "No"
    ELSE IF
    FieldC equals "Yes"
    THEN
    Set Field A to "No"
    Set FiedlB to "No"

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