Conversion from crmForm to Xrm.Page Not Working RRS feed

  • Question

  • For the Account entity, we have a customization that allows us to standardize the entry of address fields that are text. Our customization will replace the text fields (e.g., country) with an option set during the OnLoad event. That way users are presented with a pre-defined option set of countries, rather than entering it themselves.  

    The problem is we're unable to save the values to the DB during the OnSave event. The code works fine with CRM 4.0 JavaScript, but when I try to use the Xrm.Page reference, it breaks. 

    Here is the current code that works:

    if (Xrm.Page.getAttribute("address1_country") != null)

    { Xrm.Page.getAttribute("address1_country").setValue(crmForm.all.address1_country.DataValue); }

    The moment I try to change it to below, it breaks:

    if (Xrm.Page.getAttribute("address1_country") != null) {
    The problem is the value isn't actually saved to the database yet, so I'm not sure if getValue() is properly used here. I need to grab the "text" that is being selected and apply it to the save operation. 

    Friday, May 29, 2015 3:36 PM

All replies

  • I think the problem is that you are in a circular reference here.  You are trying to 'set' address1_country and 'get' the value of address1_country in the same line of code.  Doesn't make sense unless I am missing something?

    Seems like maybe you need a new custom field called new_countryoptionset that is an option set of all the countries, and then hide the address1_country field.  When the user selects a value from the custom field, grab the text of that option and set the address1_country field then.

    if (Xrm.Page.getAttribute("new_countryoptionset") != null) {

    Friday, May 29, 2015 6:26 PM
  • The logic is like that because of our customization. During the OnLoad, we replace address1_country with a picklist value populated from another entity, and that entity has a record with all the picklist values. In reality, it's really populating what's being selected in the option set. Kind of weird that it works perfectly fine with crmForm, but not Xrm.Page. But I do see the confusion with the logic. 
    Friday, May 29, 2015 7:25 PM
  • It may work because the crmForm is a separate object from the Xrm.Page object?  crmForm is for backwards compatibility to v4.0 and I think it will disappear if you go to v2013, and definitely will go away in v2015.

    You may need to re-architect the customization to support the newer versions. 

    Friday, May 29, 2015 7:29 PM
  • Hi,

    Try with setting a new value in a variable and then setting it up. Just a thought !

    Also, make sure field is not' read only' as you have to write an extra line of code in order to save it.

    if (Xrm.Page.getAttribute("address1_country") != null)
        var temp = Xrm.Page.getAttribute("address1_country").getValue();





    • Edited by H.Desai Monday, June 1, 2015 12:53 AM
    Monday, June 1, 2015 12:44 AM
  • Did you try to create another field and then tested it?

    Microsoft Dynamics CRM Training|Our Blog | Follow US | Our Facebook Page | Microsoft Dynamics CRM 2011 Application Design
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Monday, June 1, 2015 5:07 AM