locked
Set a field's value based upon Lookup field selection RRS feed

  • Question

  • Hello,

    I am trying to determine if I have to write some custom code or if CRM 2013 on premise has this functionality OOB.

    I have two fields. One is the State/Province field provided by CRM 2013 OOB set to readonly (locked). The other is a lookup field I created.

    The lookup field comes from a custom entity with all the states and their ISO codes. The lookup field has all the states fullnames. This is appreciated by the users and management over free form text entry.

    However we still need to update original State/Province field with the ISO code from the selected state in the Lookup.

    Not finding anything  to update fields from a lookup I was about to turn to write some custom code and thought it would be smart to first check with all you brainiacs.

    So how would you recommend going about finding the selected state's iso code and updating the State/Province field.

    Thank You

    Monday, January 13, 2014 10:43 PM

All replies

  • You need to make ODATA call to get ISO Code of State selected in lookup and update the state/province field with that. 
    Monday, January 13, 2014 11:39 PM
  • Hello,

    Please check following link :

    http://vikramxrm.blogspot.ae/2012/04/auto-populate-form-fields-with-selected.html


    Hope this helps. If you get answer of your question, please mark the response as an answer and vote as helpful !!!
    Vikram Singh. !!!  My Blog

    Tuesday, January 14, 2014 4:16 AM
  • HI 

    Try this.. this example is from sdk. 

    function LoadEvent() 
    {
         var sLookupValue = new Array();
        if (Xrm.Page.getAttribute("new_lookupfield").getValue() == null)
        { return ""; }
        sLookupValue = Xrm.Page.getAttribute("new_lookupfield").getValue();
        if (sLookupValue[0] != null) {
            var vLookid = sLookupValue[0].id;
        retrieveAccount(vLookid)
        }
    }

    function retrieveAccount(vLookId) {
     SDK.JQuery.retrieveRecord(
         vLookId,
         "new_customentityname",
         null, null,
         function (customentitynametogetstate&iso) {      
    Xrm.Page.getAttribute("new_state/province").setValue((customentityname.new_customeentityField));
         },
         errorHandler
       );
    }

    function errorHandler(error) {
     alert(error.message);
    }

    You need to add supporting jquery, jquery1.4.1min and json files.

    Hope this helps..


    Tuesday, January 14, 2014 5:20 AM