Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to auto fill field in a form based on a unique value and values from another form
    text
    copied!<p>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.</p> <p>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.</p> <p>For example the Booking Screen form has:</p> <p>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.</p> <p>We can either do this by workflow or java script? I would prefer java script as workflows are asynchronous.</p> <p>How can I do this?</p> <p>Using the above mentioned libraries and some searching I have come up with this</p> <pre><code>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); } }); } </code></pre> <p>But this is only the way to set up the retrieve call right?</p> <p>I have added <em>json2</em> and <em>jquery 1.4.1.min</em> library.</p> <p>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..</p> <p>How do I do this?</p> <p>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;</p> <pre><code> 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); } }); } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload