How to create a field mapping for a custom field in order to transfer data....

Hello all, can anyone show me how to create a field mapping for a custom field in order to transfer data from the source entity to the target entity in form design using Jscrip.

  • Hello Linvex,

    The custom field mapping through JScript can be achieved using JSon. Given below is a code snippet for custom field mapping with a Scenario. 


    Let’s assume that the Account and Contact entity forms are customized with a custom field (Lookup) – ‘Location’. When the contact record is created with Parent Customer, the Location value from Account should be mapped automatically with the contact record.

    Code Snippet:



    //*********Function: On Save method to retrieve and populate the Location from Account to Contact record********


    function MapCustomerLocation() {

        var locationVal = null;

        if ("parentcustomerid").getValue() != null) {

      //Get the Parent Customer Id from the lookup field on the Contact record

            var parentCustomer ="parentcustomerid").getValue();

            if (parentCustomer!= null && parentCustomer.length > 0) {

      //Get CRM server URL

                var serverUrl = Xrm.Page.context.getServerUrl();

                var ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";

                var odataSelect = ODataPath + "/AccountSet?$filter= AccountId eq guid'" + parentCustomer [0].id + "'&$select=new_Location";

    //Json to retrieve the Location field value from the Account record


                    type: "GET",

                    async: false,

                    contentType: "application/json; charset=utf-8",

                    datatype: "json",

                    url: odataSelect,

                    beforeSend: function (XMLHttpRequest) {

                        XMLHttpRequest.setRequestHeader("Accept", "application/json");


                    success: function (data, textStatus, XmlHttpRequest) {

                        if (data.d && data.d.results != null && data.d.results.length > 0) {

                            if (data.d.results[0]["new_MetroArea"] != null) {

                                var lookupValue = new Array();

                                lookupValue[0] = new Object();

                                lookupValue[0].id = data.d.results[0]["new_Location"].Id;

                                lookupValue[0].name = data.d.results[0]["new_ Location "].Name;

                                lookupValue[0].entityType = data.d.results[0]["new_ Location "].LogicalName;

                                locationVal = lookupValue;




                    error: function (XmlHttpRequest, textStatus, errorThrown) { }




    //Map the retrieved location value from Account to the Contact record"new_locationid").setValue(locationVal);



    Hope this helps.


    Congruent Info - Tech