Hi I just started to use client side scripting, although it might me those another goto goggle search community question , but believe me i have scourged google and communities but to link my query into a single unit always fail , let me describe the problem statement to give you a better idea
i have created two custom entity named cts_agent,cts_cases, now i need to auto populate all the fields of cts_cases which are read only property fields except one which is agent id (whole number) which is mapped to cts_agent entity form .
if it have been an entity reference field i could use the query expression to fetch the details from the agents_form and auto populate the details in my cts_form but i need to write a js query which could take the agent id and fetch me those details. after fetching the details will be presented in a json format from where i need to populate the details in my cts_cases form which is also another problem i am unable to address, the dynamical retrival of guid value and autopopulating the cts_cases with json are my two blockage i am facing . i have written a code for static version though
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/cts_agents(00000000-0000-0000-0000-000000000000)?$select=cts_addressline1,cts_addressline2,cts_addressline3,cts_city,cts_country,cts_email,cts_fax,cts_mobilenumber,cts_name,cts_phonenumber,cts_state,cts_zipcode", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.onreadystatechange = function() {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var cts_addressline1 = result["cts_addressline1"];
var cts_addressline2 = result["cts_addressline2"];
var cts_addressline3 = result["cts_addressline3"];
var cts_city = result["cts_city"];
var cts_country = result["cts_country"];
var cts_email = result["cts_email"];
var cts_fax = result["cts_fax"];
var cts_mobilenumber = result["cts_mobilenumber"];
var cts_name = result["cts_name"];
var cts_phonenumber = result["cts_phonenumber"];
var cts_state = result["cts_state"];
var cts_zipcode = result["cts_zipcode"];
var cts_zipcode_formatted = result["cts_zipcode@OData.Community.Display.V1.FormattedValue"];
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
hope i am able to give a detailed overview of my problem.Thanks in advance for going through it, again sorry to post another goto google search problem.believe me i tried to find it before posting it. thanks :)