locked
Auto populate country field in user's according to the language set RRS feed

  • Question

  • Hi,

    I have been working on auto populate of "field of language"

    I have installed one more language in crm that is "chinese" additional to english (default).

    I created two user, one with english and one with "chinese" and also a custom field "country" as optionset with values "india" and "china'.

    My requirement is using javascript :

    If i open user1 (english) then - in custome field country - value should be auto populated to "India"

    If i open user2 (chinese) then - in custome field country - value should be auto populated to "China"

    Monday, February 10, 2014 6:12 AM

Answers

  • Hi Amy,

    You have to retrieve the country of the logged in user by querying the systemuser entity and then you would be able to populate the optionset depending upon it.

    Thanks


    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful" Thank you, DT

    • Marked as answer by Amy.4 Monday, February 10, 2014 10:28 AM
    Monday, February 10, 2014 7:21 AM
  • Hi,

    Take a look at the optionset for the custom field you have and note the two ints that are connected to the values (India and China). Then you have a funtion on the onload script of systemuser which is something like the folowing

    var lcid = Xrm.Page.context.getUserLcid();
    if (lcid==1033) 
      Xrm.Page.getAttribute("new_usercountry").setValue(290180001);
    else
      Xrm.Page.getAttribute("new_usercountry").setValue(290180002);
    That code will look at the lcid of the user, which is what language is chosen in CRM. 1033 is US English and if that is chosen you will set the field "new_usercountry" to the value 290180001, otherwise set it to 290180002. You will obviously need to change the numbers to correct ones and change the field name but otherwise this would do what you want. You probably want to change the "else" to "else if" and check fot the chinese version you have installed, you can find the lcids of languages here


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    • Marked as answer by Amy.4 Monday, February 10, 2014 10:25 AM
    Monday, February 10, 2014 8:45 AM

All replies

  • Hi Amy,

    You have to retrieve the country of the logged in user by querying the systemuser entity and then you would be able to populate the optionset depending upon it.

    Thanks


    If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful" Thank you, DT

    • Marked as answer by Amy.4 Monday, February 10, 2014 10:28 AM
    Monday, February 10, 2014 7:21 AM
  • Hi,

    Take a look at the optionset for the custom field you have and note the two ints that are connected to the values (India and China). Then you have a funtion on the onload script of systemuser which is something like the folowing

    var lcid = Xrm.Page.context.getUserLcid();
    if (lcid==1033) 
      Xrm.Page.getAttribute("new_usercountry").setValue(290180001);
    else
      Xrm.Page.getAttribute("new_usercountry").setValue(290180002);
    That code will look at the lcid of the user, which is what language is chosen in CRM. 1033 is US English and if that is chosen you will set the field "new_usercountry" to the value 290180001, otherwise set it to 290180002. You will obviously need to change the numbers to correct ones and change the field name but otherwise this would do what you want. You probably want to change the "else" to "else if" and check fot the chinese version you have installed, you can find the lcids of languages here


    Rickard Norström Developer CRM-Konsulterna
    http://www.crmkonsulterna.se
    Swedish Dynamics CRM Forum: http://www.crmforum.se
    My Blog: http://rickardnorstrom.blogspot.se

    • Marked as answer by Amy.4 Monday, February 10, 2014 10:25 AM
    Monday, February 10, 2014 8:45 AM