locked
Need help for Jscript beginner RRS feed

  • Question

  • I am a complete beginner when it comes to Jscript and wanted to see if someone could help me with the code that is currently producing an error.

    We are a Distributor for AT&T and sell 1-10 line customers.  For each phone line we sell per order we need to capture information like the exact phone number, features on each line etc.  I have a section created for each of the 10 phone lines but don't want all 10 sections visible if the customer only has 1 phone line. 

    All sections are hidden by default and want the necessary number of sections to populate based on the dropdown list selection of 1-10.  I have the onchange event setup on the Number of Lines dropdown field and am 99% sure that the problem is with the script.  Again, I am complete beginner when it comes to Jscript but any help would be greatly appreciated. 

    function onTypeChange(){
        if( Xrm.Page.getAttribute("new_oflines").getValue() ==0)
        {
            Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
        }
        else if( Xrm.Page.getAttribute("new_oflines").getValue() ==1)
        {
            Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
    }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==2)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
        }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==3)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
     }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==4)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
     }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==5)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
     }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==6)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
     }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==7)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
     }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==8)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(false);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
    }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==9)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(false);
    }
    else if(Xrm.Page.getAttribute("new_type").getValue() ==10)
        {
           Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_1").setVisible(true);
            Xrm.Page.ui.tabs.get("tab_10").sections.get("general_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_3").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_4").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_5").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_6").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_7").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_8").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_9").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_10").setVisible(true);
     Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_11").setVisible(true);
        }
            return;
        }

        Xrm.Page.ui.tabs.get("tab_10").setVisible(true);
    }

    Friday, September 6, 2013 8:59 PM

Answers

  • assuming that the field new_type accepts values from 1 to 10 (if is an optionset is necessary to check the if the value has a prefix)
    and you have 10 sections called tab_10_section_1, tab_10_section_2, ..., tab_10_section_10
    your code can be:

    function onTypeChange()
    {
    	var lines = parseInt(Xrm.Page.getAttribute("new_oflines").getValue());
    	for (var j=1; j<=lines; j++)
    	{
    		Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_"+j).setVisible(true);
    	}
    
    	for (var k=lines+1; k<=10; k++)
    	{
    		Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_"+k).setVisible(false);
    	}
    	Xrm.Page.ui.tabs.get("tab_10").setVisible(true);
    }


    My blog: www.crmanswers.net

    • Proposed as answer by Mamatha Swamy Friday, September 6, 2013 9:16 PM
    • Marked as answer by DIDDYXPPRO Friday, September 6, 2013 11:13 PM
    Friday, September 6, 2013 9:14 PM

All replies

  • assuming that the field new_type accepts values from 1 to 10 (if is an optionset is necessary to check the if the value has a prefix)
    and you have 10 sections called tab_10_section_1, tab_10_section_2, ..., tab_10_section_10
    your code can be:

    function onTypeChange()
    {
    	var lines = parseInt(Xrm.Page.getAttribute("new_oflines").getValue());
    	for (var j=1; j<=lines; j++)
    	{
    		Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_"+j).setVisible(true);
    	}
    
    	for (var k=lines+1; k<=10; k++)
    	{
    		Xrm.Page.ui.tabs.get("tab_10").sections.get("tab_10_section_"+k).setVisible(false);
    	}
    	Xrm.Page.ui.tabs.get("tab_10").setVisible(true);
    }


    My blog: www.crmanswers.net

    • Proposed as answer by Mamatha Swamy Friday, September 6, 2013 9:16 PM
    • Marked as answer by DIDDYXPPRO Friday, September 6, 2013 11:13 PM
    Friday, September 6, 2013 9:14 PM
  • That worked.  Thanks for your help.  Do you or anyone you know offer remote services where I can pay you to add a list of Jscript or customizations to our CRM?
    Friday, September 6, 2013 11:09 PM
  • Glad you solved. Feel free to contact me through linkedin (there is a link on my blog) or email: firstname.lastname@gmail.com

    My blog: www.crmanswers.net

    Friday, September 6, 2013 11:25 PM