Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

How do you write an if statement to equal an optionset value?

Posted on by Microsoft Employee

I am trying to write an if statement, that will check to see if remittancefile is selected as No in the option field.  If so then I want it to set the values of the following fields.  I am pretty sure I have the set values correct.  I just cannot get the if statement working properly.  I am not sure if it is actually the if statement or the get attribute I am using.  Any help is greatly appriciated.

Code:

function NAIfNo( )

{

var Name = Xrm.Page.data.entity.attributes.get("new_deadlinetime");

//get the value of remittance file

var file = Xrm.Page.data.entity.attributes.get("new_remittancefile");

 

//check to see if remittance file equals “no”

//the optionset value data for no is 100000001

if (file == No)

                                {

                //set values to following fields if remittance file is “no”

                Xrm.Page.getAttribute("new_remittanceformat").setValue(999999999);

                Xrm.Page.getAttribute("new_dpremittance").setValue(999999999);

                Xrm.Page.getAttribute("new_deliveryremittance").setValue(999999999);

                Xrm.Page.getAttribute("new_remittancepassword").setValue(999999999);

                Xrm.Page.getAttribute("new_frequencyremittance").setValue(999999999);

                Name.setValue("N/A");

                Xrm.Page.getAttribute("new_paperstatement").setValue(999999999);

 

                                }

}

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    Re: How do you write an if statement to equal an optionset value?

    I finally found what I was looking for, I hope this will help someone in the future.

    function NAIfNo( )
    {
    var Name = Xrm.Page.data.entity.attributes.get("new_deadlinetime");
    //my issue was here, I needed to get the optionset and display it as text
    var file = Xrm.Page.getAttribute("new_remittancefile").getSelectedOption().text

    if (file == "No")
      {

     Xrm.Page.getAttribute("new_remittanceformat").setValue(999999999);
     Xrm.Page.getAttribute("new_dpremittance").setValue(999999999);
     Xrm.Page.getAttribute("new_deliveryremittance").setValue(999999999);
     Xrm.Page.getAttribute("new_remittancepassword").setValue(999999999);
     Xrm.Page.getAttribute("new_frequencyremittance").setValue(999999999);
     Name.setValue("N/A");
     Xrm.Page.getAttribute("new_paperstatement").setValue(999999999);
     
      }

    }

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,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans