locked
Javascript Newbie. For Loop..... RRS feed

  • Question

  • Hi there...

    I have written a code below in Javascript:

    Xrm.Page.ui.tabs.get(1).setVisible(false);
    Xrm.Page.ui.tabs.get(2).setVisible(false);
    Xrm.Page.ui.tabs.get(3).setVisible(false);
    Xrm.Page.ui.tabs.get(4).setVisible(false);
    Xrm.Page.ui.tabs.get(5).setVisible(false);
    Xrm.Page.ui.tabs.get(6).setVisible(false);
    Xrm.Page.ui.tabs.get(7).setVisible(false);
    Xrm.Page.ui.tabs.get(8).setVisible(false);

     

    How do I loop through all the tabs and set them as false instead of doing it as above?

    Tuesday, November 22, 2011 2:25 PM

Answers

All replies

  • Hello,

    Try following:

    for (var i = 1; i < 9; i++)

    Xrm.Page.ui.tabs.get(i).setVisible(false);

     

    Here is good resource about JavaScript - http://www.w3schools.com


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Tuesday, November 22, 2011 2:30 PM
    Moderator
  • Thanks alot for your help. Works perfectly.

    Another question would the for loop work for this statement too?

    var ciType = Xrm.Page.data.entity.attributes.get("apitil_citype");
    var ciTypeVal = ciType.getValue();

     

    if (ciTypeVal == "345550000")
    {
    Xrm.Page.ui.tabs.get(i).setVisible(true);
    }

    if (ciTypeVal == "345550001")
    {
    Xrm.Page.ui.tabs.get(2).setVisible(true);
    }

    if (ciTypeVal == "345550002")
    {
    Xrm.Page.ui.tabs.get(3).setVisible(true);
    }

    etc......

     

    Tuesday, November 22, 2011 2:52 PM
  • Hello,

    Yes, it would but you should use i instead hardcoded numbers like:

    if (ciTypeVal == "345550000")
    {
    Xrm.Page.ui.tabs.get(i).setVisible(true);
    }

    if (ciTypeVal == "345550001")
    {
    Xrm.Page.ui.tabs.get(i).setVisible(true);
    }

    if (ciTypeVal == "345550002")
    {
    Xrm.Page.ui.tabs.get(i).setVisible(true);
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Tuesday, November 22, 2011 2:55 PM
    Moderator
  • Thanks very much for your help!
    Tuesday, November 22, 2011 4:01 PM