I have a 4 to 5 custom entities with one form each. There is going to be a fluent progress from one form to another e.g, the first entity "Booking Screen" has one form, after filling it the user will move to the next entity and fill its form and the next and so on.

I want the proceeding form to get some information based on the forms filled earlier to be uploaded based on a booking number that will be assigned on the first booking screen.

For example the Booking Screen form has:

First name, last name, booking number (a unique id) and other info...I would like the next form to have the option enter the unique id and then auto-fill the name fields or other information from the first form.

We can either do this by workflow or java script? I would prefer java script as workflows are asynchronous.

How can I do this?

Using the above mentioned libraries and some searching I have come up with this

```
function retrieveRecord(id, odataSetName, successCallback, errorCallback) {

   var context = Xrm.Page.context;

   var serverUrl = context.getServerUrl();

   var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

   //Asynchronous AJAX function to Retrieve a CRM record using OData

   $.ajax({

   type: "GET",

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

   datatype: "json",

   url: serverUrl + ODATA_ENDPOINT + "/" + odataSetName + "(guid'" + id + "')",

   beforeSend: function (XMLHttpRequest) {

       //Specifying this header ensures that the results will be returned as JSON.            

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

   },

   success: function (data, textStatus, XmlHttpRequest) {

       if (successCallback) {

           successCallback(data.d, textStatus, XmlHttpRequest);

       }

   },

   error: function (XmlHttpRequest, textStatus, errorThrown) {

       if (errorCallback)

           errorCallback(XmlHttpRequest, textStatus, errorThrown);

       else

           errorHandler(XmlHttpRequest, textStatus, errorThrown);

   }

});

}

```

But this is only the way to set up the retrieve call right?

I have added *json2* and *jquery 1.4.1.min* library.

Now I have added this on my ONLOAD event of the form that I want to be populated. I want that when I add the booking number on my form (this will go on the ON CHANGE event of the text field I guess) it should retrieve the first name, last name, middle name, SSN# from the main form i.e booking screen..

How do I do this?

my final code but it is not setting any values on the form fields
function getContactDetails()
{
 var lookUpObjectValue = Xrm.Page.getAttribute("inmate\_lookupbookingscree").getValue();
 if ((lookUpObjectValue != null))
 {
 var lookuptextvalue = lookUpObjectValue[0].name;

```
    var lookupid = lookUpObjectValue[0].id;
    //alert(lookupid);

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

//The XRM OData end-point
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";

//var odataSetName = "ContactSet";

var odataSelect = serverUrl + ODATA_ENDPOINT + "/" + "(guid'" + lookupid + "')";

//alert(odataSelect);

$.ajax({
    type: "GET",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: odataSelect,
    beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
    success: function (data, textStatus, XmlHttpRequest) {

         var result_contact= data.d;

        //alert(result_contact.AccountNumber);
                    //replace the fields with the fields on your entity
                    Xrm.Page.getAttribute("inmate_firstname").setValue(result_contact.inmate_firstname);
                    Xrm.Page.getAttribute("inmate_lastname").setValue(result_contact.inmate_lastname);

    },
    error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
});

}

```

}