none
Can anyone help me with this Java Script for the Appointment entity in CRM 2011?

    Question

  • Hello... I am really a beginner with Java Script and I am asking again for help...

    I need a script so that when some options in a pick list in the Appointment entity are selected, a tab is hidden.

    I have tried what you see below, on load in the form and on change on the pick list field,  but it gives error messages, could anyone let me know what needs to be corrected?

    Thanks

    function hidetabfornonsellingactivities()
    {
    if(Xrm.Page.getAttribute("scapa_appointmenttype").getValue() == "Exhibition" || Xrm.Page.getAttribute("scapa_appointmenttype").getValue() == "Holiday" || Xrm.Page.getAttribute("scapa_appointmenttype").getValue() == "Home Office" || Xrm.Page.getAttribute("scapa_appointmenttype").getValue() == "Illness" || Xrm.Page.getAttribute("scapa_appointmenttype").getValue() == "Scapa Internal Meeting" || Xrm.Page.getAttribute("scapa_appointmenttype").getValue() == "Training (Employee)")
    {
    Xrm.Page.ui.tabs.get("tab_5").SetVisible(false);
    }
    else
    {
    Xrm.Page.ui.tabs.get("tab_5").SetVisible(true)
    }
    }

    Friday, February 24, 2012 3:41 PM

Answers

  • I'm not very good in Italian. Luckily I can use google translator. Try to use following code:

    function hidetabfornonsellingactivities()
    {
    	var tabtohide = Xrm.Page.ui.tabs.get(5);
    	if (tabtohide == null)
    	{
    		alert("Tab with index 5 was not found!");
    		return;
    	}
    
    	if(Xrm.Page.getAttribute("scapa_appointmenttype").getValue() != null
    	&& (Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Exhibition" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Holiday" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Home Office" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Illness" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Scapa Internal Meeting" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Training (Employee)"))
    	{
    		tabtohide.setVisible(false);
    	}
    	else
    	{
    		tabtohide.setVisible(true);
    	}
    }



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Friday, February 24, 2012 4:35 PM

All replies

  • Hi 

    While using option set , syntax is:

    Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;

    • Proposed as answer by KirstenClapham Friday, February 24, 2012 4:07 PM
    Friday, February 24, 2012 4:06 PM
  • Hi 

    While using option set , syntax is:

    Xrm.Page.getAttribute(“CRMFieldSchemaName”).getSelectedOption().text;

    @CRMDevlpr Comparison of getValue() of with picklist would not generate error because getValue for picklist will give string other thing that it would not work.

    @Silvia Try to use following code:

    function hidetabfornonsellingactivities()
    {
    	if(Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Exhibition" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Holiday" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Home Office" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Illness" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Scapa Internal Meeting" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Training (Employee)")
    	{
    		Xrm.Page.ui.tabs.get(5).setVisible(false);
    	}
    	else
    	{
    		Xrm.Page.ui.tabs.get(5).setVisible(true);
    	}
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Proposed as answer by CRMDevlpr Friday, February 24, 2012 4:18 PM
    Friday, February 24, 2012 4:10 PM
  • Hi Andrii

    My intention was to mention that to compare picklist value we need to use getselectedvalue instead of getValue. I did not mean to say that getValue is the reason for error.

    But anyways, thanks for your clarification.

    Might be helpful for others.

    I was too brief in reply

    Friday, February 24, 2012 4:18 PM
  • Thanks Andrii

    I have tried the script you suggest but it still gives an error:

    "there is a error with this field's customised event

    field: window

    event: on load

    error: previsto oggetto"

    Friday, February 24, 2012 4:25 PM
  • Hi

    What does the error says? Is it object expected?

    You need to call the function on an event. See the screenshot above. Have you done this?

    Friday, February 24, 2012 4:34 PM
  • I'm not very good in Italian. Luckily I can use google translator. Try to use following code:

    function hidetabfornonsellingactivities()
    {
    	var tabtohide = Xrm.Page.ui.tabs.get(5);
    	if (tabtohide == null)
    	{
    		alert("Tab with index 5 was not found!");
    		return;
    	}
    
    	if(Xrm.Page.getAttribute("scapa_appointmenttype").getValue() != null
    	&& (Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Exhibition" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Holiday" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Home Office" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Illness" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Scapa Internal Meeting" 
    	|| Xrm.Page.getAttribute("scapa_appointmenttype").getSelectedOption().text == "Training (Employee)"))
    	{
    		tabtohide.setVisible(false);
    	}
    	else
    	{
    		tabtohide.setVisible(true);
    	}
    }



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    Friday, February 24, 2012 4:35 PM
  • Yes, it says "object expected".

    I put the script on Load in the form, and on change on the pick list field.

    Friday, February 24, 2012 4:37 PM
  • Many thanks! This code works perfectly without any error messages.
    Friday, February 24, 2012 7:36 PM