locked
Finding the attribute Name Xrm.Page.getAttribute("new_adressline2").setValue(Address2); RRS feed

  • Question

  • Hi

    I have dropdown name it as city. it's conists of India, US, UK etc...with corresponding values 1,2,3 respectively...

     I want to  set the values to Names only not setvalue.. how can i set name..

    -Regards,

     


    Rammohan

    Monday, April 16, 2012 11:34 AM

Answers

  • Hi Ram,

    i haven't get your question,

    but i know how to set a text for a piclist control in CRM

    this what you need

    function test()
    {
    var att=document.getElementById("customertypecode");
    for(i=0;i<att.options.length;i++)
    {
    if(att.options[i].innerText=="Competitor")
    {
    att.options[i].innerText="sandeep"
    }
    }
    
    }

    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    • Proposed as answer by san Sanz Tuesday, April 17, 2012 6:48 AM
    • Edited by san Sanz Tuesday, April 17, 2012 6:50 AM
    • Marked as answer by Rammohan Ammiti Tuesday, April 17, 2012 7:53 AM
    Tuesday, April 17, 2012 6:47 AM

All replies

  • You can loop through all the options of the OptionSet attribute and compare the text to get the desired value.

    setOptionSetByOptionText("new_city", "India");
    
    
    setOptionSetByOptionText = function(optionsetAttribute, optionText)
    {
    	var options = Xrm.Page.getAttribute(optionsetAttribute).getOptions();
    	for(i = 0; i < options.length; i++)
    	{
    		if (options[i].text == optionText)
    			Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value);
    	}
    }

    Monday, April 16, 2012 1:25 PM
  • Hi

     Thanks for your reply..

    My question is: i want to assing the Name not value...

    I want to assing the Dropdown name to text box not Name.. how can i set Name to Textbox field?


    Rammohan

    Tuesday, April 17, 2012 3:24 AM
  • Hi Rammohan,

    You mean you want to get or set the label of the attribute?

    I am not quite clear with your requirement.

    Tuesday, April 17, 2012 5:21 AM
  • Hi

       I want that label Text only only

    Example: I have Option set        Item : India       values=1

                                                        Item : USA        values=2

                                                        Item : UK          values=3

    if i write the code like     Xrm.Page.getAttribute("new_city").setValue(city);

    I will get the values right?

     But i want to get the Name like USA  for instead of set value i have to change the syntax to get the name

    pls suggest it

     

                   


    Rammohan

    Tuesday, April 17, 2012 5:41 AM
  • Ohhh..  You mean you want to get the text value of the selected option rather than the integer value, is that correct?

    If so, you can use getText() instead of getValue()

    Xrm.Page.getAttribute("new_city").getText();

    Read the following post for more details

    http://asimsajjad.blogspot.com/2011/06/how-to-retrieve-optionset-text-and.html

    Tuesday, April 17, 2012 5:50 AM
  • Hi

      I have to set the Text to  another control that is why i have given the clearly mentioned

    Xrm.Page.getAttribute("new_city").setValue(city);

     how to set that text to new control..

     getText() method is not working and setText() also not working.. .. pls suggest on this


    Rammohan

    Tuesday, April 17, 2012 6:07 AM
  • There's no setText() method. For setting the value of the option set with the text value, I've already mentioned in the second post.

    Have you tried that?

    You can loop through all the options of the OptionSet attribute and compare the text to get the desired value.

    setOptionSetByOptionText("new_city", "India");
    
    
    setOptionSetByOptionText = function(optionsetAttribute, optionText)
    {
    	var options = Xrm.Page.getAttribute(optionsetAttribute).getOptions();
    	for(i = 0; i < options.length; i++)
    	{
    		if (options[i].text == optionText)
    			Xrm.Page.getAttribute(optionsetAttribute).setValue(options[i].value);
    	}
    }

    Tuesday, April 17, 2012 6:18 AM
  • Hi Ram,

    i haven't get your question,

    but i know how to set a text for a piclist control in CRM

    this what you need

    function test()
    {
    var att=document.getElementById("customertypecode");
    for(i=0;i<att.options.length;i++)
    {
    if(att.options[i].innerText=="Competitor")
    {
    att.options[i].innerText="sandeep"
    }
    }
    
    }

    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".


    • Proposed as answer by san Sanz Tuesday, April 17, 2012 6:48 AM
    • Edited by san Sanz Tuesday, April 17, 2012 6:50 AM
    • Marked as answer by Rammohan Ammiti Tuesday, April 17, 2012 7:53 AM
    Tuesday, April 17, 2012 6:47 AM
  • Hi Sanz,

    Any direct interaction with the HTML Document Object Model (DOM) in Form Scripting is not supported by Microsoft and will probably not be upgradable.

    Tuesday, April 17, 2012 6:53 AM
  • Hi Linn,

    according my knowledge it should work


    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

    Tuesday, April 17, 2012 7:57 AM
  • Hi Sanz and Rammohan,

    Here's the supported way for your solution in case you're interested in.

    replaceOptionText("new_city", "USA", "United States of America");
    
    replaceOptionText = function(optionsetAttribute, oldOptionText, newOptionText)
    {
    	var options = Xrm.Page.getAttribute(optionsetAttribute).getOptions();
    	for(i = 0; i < options.length; i++)
    	{debugger;
    		if (options[i].text == oldOptionText)
    		{
    			options[i].text = newOptionText;
    			var currentValue = Xrm.Page.getAttribute(optionsetAttribute).getValue();
    			Xrm.Page.getControl(optionsetAttribute).removeOption(options[i].value);
    			Xrm.Page.getControl(optionsetAttribute).addOption(options[i], i + 1);
    			if (currentValue == options[i].value)
    				Xrm.Page.getAttribute(optionsetAttribute).setValue(currentValue);
    			return;
    		}
    	}
    }

    Tuesday, April 17, 2012 8:37 AM