Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 79901

How to return value in javscript using odata call

$
0
0

Hello,

I have a function which calls some attributes and these values must be returned through the function. can anyone help.

function mat(mid) {
var o;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/one_materials(" + mid + ")?$select=one_description,one_manufacturer,one_manufacturercode,one_unitcost", 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 one_description = result["one_description"];
if (one_description != null) {
Xrm.Page.getAttribute("one_description").setValue(one_description);
}

var one_manufacturer = result["one_manufacturer"];
if (one_manufacturer != null) {
Xrm.Page.getAttribute("one_supplier").setValue(one_manufacturer);
}
var one_manufacturer_formatted = result["one_manufacturer@OData.Community.Display.V1.FormattedValue"];
var one_manufacturercode = result["one_manufacturercode"];
if (one_manufacturercode != null) {
Xrm.Page.getAttribute("one_partno").setValue(one_manufacturercode);
}
var one_unitcost = result["one_unitcost"];
if (one_unitcost != null) {
Xrm.Page.getAttribute("one_materialcost").setValue(one_unitcost);
o = one_unitcost;
var u;
Xrm.Page.getAttribute("one_unit").setValue(1);
Xrm.Page.getControl("one_unit").setFocus();
u = Xrm.Page.getAttribute("one_unit").getValue();
var totmatcost = o * u;
Xrm.Page.getAttribute("one_totalmaterialcost").setValue(totmatcost);
}
var one_unitcost_formatted = result["one_unitcost@OData.Community.Display.V1.FormattedValue"];

} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};

req.send();
}

I would like to return the value from one_unitcost attribute. I just need to know which place in the function i should return this value.


Viewing all articles
Browse latest Browse all 79901

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>