locked
Poplulate a Text field with a Picklist value RRS feed

  • Question

  • Hello all,

    I would like to populate a text field with a picklist value.
    Due to my lack of knowledge of javascript I don't seem to be able to do it...

    I would like the field "name" (text field) to be filled in with the relationship type "customertypecode" (picklist). So only when the "customertypecode" is "project" the text field has to be filled in with "Project - ".

    Thx!

    PS does anyone know good resources to learn javascript so i can apply it in ms crm?
    Wednesday, October 7, 2009 9:17 AM

Answers

  • Try this:

    crmForm.all.name.DataValue = (crmForm.all.customertypecode.DataValue != null && crmForm.all.customertypecode.SelectedText == "project") ? "Project -" : "";
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by brosimba Wednesday, October 7, 2009 12:02 PM
    Wednesday, October 7, 2009 9:56 AM
    Moderator

All replies

  • Hi.

    For knowledge about javascript I use http://www.w3schools.com/

    For your case to populate selected value text you can use following script place ro onchange event handler of picklist field:

    crmForm.all.<string field>.DataValue = "Project" + (crmForm.all.customertypecode.DataValue == null ? "" : crmForm.all.customertypecode.SelectedText);
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, October 7, 2009 9:23 AM
    Moderator
  • Hi,

    you can wirte following js onchange of customertypecode

    if(crmForm.all.customertypecode.SelectedText=="Project")
              crmForm.all.name.DataValue="Project"+crmForm.all.customertypecode.SelectedText;

    Hope it will help !!
    Mahain
    Wednesday, October 7, 2009 9:28 AM
    Moderator
  • Hmmm its not working yet but I'm probably not filling it in right still. Do I fill in the number of the picklist value in between the ""?

    This is what I put but I don't really know what I'm doing...


    crmForm.all.name.DataValue = "Project" + (crmForm.all.customertypecode.DataValue == null ? "12" : crmForm.all.customertypecode.SelectedText);
    Wednesday, October 7, 2009 9:34 AM
  • Hi Machender Pal,

    I tried your script but I still get an error:

    Field: customertypecode
    Even: onchange
    error: object required
    Wednesday, October 7, 2009 9:49 AM
  • Try this:

    crmForm.all.name.DataValue = crmForm.all.customertypecode.SelectedText == "project" ? "Project -" : "";
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by brosimba Wednesday, October 7, 2009 10:07 AM
    • Unmarked as answer by brosimba Wednesday, October 7, 2009 11:53 AM
    Wednesday, October 7, 2009 9:52 AM
    Moderator
  • I still get the same error...
    Wednesday, October 7, 2009 9:55 AM
  • Try this:

    crmForm.all.name.DataValue = (crmForm.all.customertypecode.DataValue != null && crmForm.all.customertypecode.SelectedText == "project") ? "Project -" : "";
    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    • Marked as answer by brosimba Wednesday, October 7, 2009 12:02 PM
    Wednesday, October 7, 2009 9:56 AM
    Moderator
  • It is filling the the text field correctly now with "Project -" when the picklist is "Project".
    The problem I have now is that I'd like to add something behind the "Project -" in the text field (manually)... But when I add something and go to the next field it'll delete it again and only the "Project -" will be left.

    How can I make it so I can still manually edit the text field if I want?
    Wednesday, October 7, 2009 11:55 AM
  • Don't change cutomertypecode field and everything will be ok.

    Truth is opened the prepared mind My blog - http://a33ik.blogspot.com
    Wednesday, October 7, 2009 11:59 AM
    Moderator
  • Is there any code onchange event of the text field. ??????




    Mahain
    Wednesday, October 7, 2009 11:59 AM
    Moderator
  • You are right... I put it on the onchange of the text field. I thought it had to go there too.

    Sorry... it works now.
    Wednesday, October 7, 2009 12:02 PM