locked
Or Function? RRS feed

  • Question

  • Is there an or function? I'm trying to use the code but with an "or" function and nothing I have tried has worked. If I delete the || "Active Client" it works fine. Is there a different or function the crm uses? Thanks for any help.

    if(Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text == "Active ASP" || "Active Client")

    Trevor

    Monday, January 14, 2013 10:55 PM

Answers

  • the correct code is:

    if(Xrm.Page.getAttribute("new_accountstatus").getText() == "Active ASP" || Xrm.Page.getAttribute("new_accountstatus").getText() == "Active Client")

    or more readable:

    var text = Xrm.Page.getAttribute("new_accountstatus").getText();
    if (text == "Active ASP" || text == "Active Client")



    Monday, January 14, 2013 10:59 PM
  • Yes, there is a logical OR in Javascript, but it cannot be used in the way you have attempted.  Instead try:

    var status = Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text;
    
    if (status == "Active ASP" || status == "Active Client") {
    
    }

    or you could use a switch statement:

    var status = Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text;
    
    switch (status) {
      case "Active ASP":
      case "Active Client":
    
        break;
      default:
    
        break;
    }


    --pogo (pat) @ pogo69.wordpress.com

    Monday, January 14, 2013 11:01 PM
  • Hi Kawasaki,There is just a small syntax error in ur code where ur code is

    if(Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text == "Active ASP" || "Active Client")

    replace the same code with below lines of code

    var option=Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text;

    if(option == "Active ASP" || option == "Active Client")

    {

    }

    • Proposed as answer by Nandan21 Tuesday, January 15, 2013 4:28 AM
    • Marked as answer by KawasakiRider03 Tuesday, January 15, 2013 2:32 PM
    Tuesday, January 15, 2013 4:28 AM

All replies

  • the correct code is:

    if(Xrm.Page.getAttribute("new_accountstatus").getText() == "Active ASP" || Xrm.Page.getAttribute("new_accountstatus").getText() == "Active Client")

    or more readable:

    var text = Xrm.Page.getAttribute("new_accountstatus").getText();
    if (text == "Active ASP" || text == "Active Client")



    Monday, January 14, 2013 10:59 PM
  • Yes, there is a logical OR in Javascript, but it cannot be used in the way you have attempted.  Instead try:

    var status = Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text;
    
    if (status == "Active ASP" || status == "Active Client") {
    
    }

    or you could use a switch statement:

    var status = Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text;
    
    switch (status) {
      case "Active ASP":
      case "Active Client":
    
        break;
      default:
    
        break;
    }


    --pogo (pat) @ pogo69.wordpress.com

    Monday, January 14, 2013 11:01 PM
  • Hi Kawasaki,There is just a small syntax error in ur code where ur code is

    if(Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text == "Active ASP" || "Active Client")

    replace the same code with below lines of code

    var option=Xrm.Page.getAttribute("new_accountstatus").getSelectedOption().text;

    if(option == "Active ASP" || option == "Active Client")

    {

    }

    • Proposed as answer by Nandan21 Tuesday, January 15, 2013 4:28 AM
    • Marked as answer by KawasakiRider03 Tuesday, January 15, 2013 2:32 PM
    Tuesday, January 15, 2013 4:28 AM
  • Thank you everyone for you help. I'm not a programmer by any means but knowing a little bit offers a lot of additional functionality with customizing the CRM. Thanks again!
    Tuesday, January 15, 2013 2:33 PM