Answered by:
hide picklist value

Question
-
Hi all,
I have a problem,I need to hide the value of the picklist in javascript,
I can't find the example from the CRM SDK4.0.
Is anybody can tell me how to write this code,thanks!
Friday, July 29, 2011 10:07 AM
Answers
-
Hi,
Hide a picklist item in CRM 4.0
function HidePickListItem(listID, value)
{
var objList = document.getElementById(listID);// If the list has never been saved, save it now
if (objList.SavedList == null)
{
var arrListe = new Array();for (var i=0; i<objList.options.length; i++)
{
arrListe[i] = new Object();
arrListe[i].value = objList.options[i].value;
arrListe[i].Libelle = objList.options[i].text;
arrListe[i].Visible = true;
}objList.SavedList = arrListe;
}for (var i=0; i<objList.SavedList.length; i++)
if (objList.SavedList[i].value == value)
objList.SavedList[i].Visible = false;for (var i=objList.options.length - 1; i>=0; i--)
if (objList.options[i].value == value)
objList.options.remove(i);
}
Show a picklist item that has been hidden in CRM 4.0function ShowPickListItem(listID, value)
{
var objList = document.getElementById(listID);if (objList.SavedList != null)
{
var selValue = null;
var indexInsertion = 0;for (var i=0; i<objList.SavedList.length; i++)
if (objList.SavedList[i].value == value)
objList.SavedList[i].Visible = true;// Keep the selected value so we can reselect it after
if (objList.selectedIndex > -1)
selValue = objList.options[objList.selectedIndex].value;// Remove all the items in the list
for (var i=objList.options.length - 1; i>=0; i--)
objList.options.remove(i);// Add the items that must be visible
for (var i=0; i<objList.SavedList.length; i++)
{
if (objList.SavedList[i].Visible)
{
var oOption = document.createElement('option');oOption.text = objList.SavedList[i].Libelle;
oOption.value = objList.SavedList[i].value;objList.options.add(oOption);
}
}// Reselect the item that was selected
for (var i=0; i<objList.options.length; i++)
if (objList.options[i].value == selValue)
objList.selectedIndex = i;
}
}
Please find the below links also:http://sliong.wordpress.com/2011/03/25/crm-4-0-hide-picklist-items-with-javascript-automatically/
http://forum.crmreports.com/topic/showing-hidden-tabs-and-picklist
Thanks & Regards, MS CRM Consultant, V.Surya.- Marked as answer by SEAN ANN Tuesday, August 2, 2011 4:36 AM
Monday, August 1, 2011 11:53 AMAnswerer -
Hi DonkeySean
To delete first value you can do:
var oField = crmForm.all.new_picklist;
oField.DeleteOption(1);KG
My Dynamics CRM Blog: http://bovoweb.blogspot.com- Marked as answer by SEAN ANN Tuesday, August 2, 2011 8:14 AM
Friday, July 29, 2011 11:15 AM
All replies
-
Hi DonkeySean
To delete first value you can do:
var oField = crmForm.all.new_picklist;
oField.DeleteOption(1);KG
My Dynamics CRM Blog: http://bovoweb.blogspot.com- Marked as answer by SEAN ANN Tuesday, August 2, 2011 8:14 AM
Friday, July 29, 2011 11:15 AM -
Hi KG,thanks for reply!
I wonder if the first value was deleted,when I trigger the OnChange,and it displays the value,can it be done?
Saturday, July 30, 2011 2:52 AM -
Assign only the values that u want to the picklist in the onload/onchange event.Saturday, July 30, 2011 6:09 AM
-
Hi,
Hide a picklist item in CRM 4.0
function HidePickListItem(listID, value)
{
var objList = document.getElementById(listID);// If the list has never been saved, save it now
if (objList.SavedList == null)
{
var arrListe = new Array();for (var i=0; i<objList.options.length; i++)
{
arrListe[i] = new Object();
arrListe[i].value = objList.options[i].value;
arrListe[i].Libelle = objList.options[i].text;
arrListe[i].Visible = true;
}objList.SavedList = arrListe;
}for (var i=0; i<objList.SavedList.length; i++)
if (objList.SavedList[i].value == value)
objList.SavedList[i].Visible = false;for (var i=objList.options.length - 1; i>=0; i--)
if (objList.options[i].value == value)
objList.options.remove(i);
}
Show a picklist item that has been hidden in CRM 4.0function ShowPickListItem(listID, value)
{
var objList = document.getElementById(listID);if (objList.SavedList != null)
{
var selValue = null;
var indexInsertion = 0;for (var i=0; i<objList.SavedList.length; i++)
if (objList.SavedList[i].value == value)
objList.SavedList[i].Visible = true;// Keep the selected value so we can reselect it after
if (objList.selectedIndex > -1)
selValue = objList.options[objList.selectedIndex].value;// Remove all the items in the list
for (var i=objList.options.length - 1; i>=0; i--)
objList.options.remove(i);// Add the items that must be visible
for (var i=0; i<objList.SavedList.length; i++)
{
if (objList.SavedList[i].Visible)
{
var oOption = document.createElement('option');oOption.text = objList.SavedList[i].Libelle;
oOption.value = objList.SavedList[i].value;objList.options.add(oOption);
}
}// Reselect the item that was selected
for (var i=0; i<objList.options.length; i++)
if (objList.options[i].value == selValue)
objList.selectedIndex = i;
}
}
Please find the below links also:http://sliong.wordpress.com/2011/03/25/crm-4-0-hide-picklist-items-with-javascript-automatically/
http://forum.crmreports.com/topic/showing-hidden-tabs-and-picklist
Thanks & Regards, MS CRM Consultant, V.Surya.- Marked as answer by SEAN ANN Tuesday, August 2, 2011 4:36 AM
Monday, August 1, 2011 11:53 AMAnswerer -
Thanks,you have solved my big problem.Tuesday, August 2, 2011 4:36 AM
-
The script is not working for CRM 2011. Error - Mothod not support. Can you tell me one for CRM 2011Monday, February 27, 2012 10:38 AM
-
I have an optionset on my opportunity that has an option that defaults as 'Converted from Lead' when someone converts a lead to an opportunity. The only time I want people to see this option is when an opp was converted from a lead - I do not want people to be able to choose this value when they are entering a new opp. In 4.0, I used .DeleteOption(7); This is what I'm using for 2011 and it works fine. My picklist/optionset field name is new_service. Option #7 is 'Converted from Lead':
if (Xrm.Page.getAttribute('new_service').getSelectedOption().text != 'Converted from Lead')
{
Xrm.Page.getControl('new_service').removeOption(7);
}Christina Bayley | CRM Administrator
Wednesday, May 2, 2012 8:49 PM