Hello everyone!
I 'm trying to this without using plugins and i can't make it. It can be done using workflow but i want to run real time when the lookup field changes value.
So here is my entity form:
I have added a Quick View Form at the bottom.
I've tried with unsupported way to do it using this code:
function getQuickValue() { setTimeout(setValue,2000); } function setValue() { var productQuickViewcost = document.getElementById("QuickViewProduct_QuickViewProduct_ral_product_ral_cost_d").getAttribute("title"); alert(productQuickViewcost); Xrm.Page.getAttribute("ral_cost").setValue(productQuickViewcost); Xrm.Page.getAttribute("ral_cost").setSubmitMode("always"); }
It doesn't work but it could work after some tweaking because using console the alert displays correctly the cost in quick view form . However i want to do this with a supported way so i found this url which uses REST Endpoint to do it.
I have tried this code :
function getCost() { var product = Xrm.Page.data.entity.attributes.get("ral_product").getValue()[0]; alert("productid =" + product.id); retrieveCost(product.id); } function retrieveCost(productId) { SDK.REST.retrieveRecord( productId, "Product", null, null, function (ral_product) { testFunction(ral_product); }, function () { alert("Error Occured."); } ); } function testFunction(ral_product) { alert(ral_product.ral_cost); }
Where "Product" is the display name of my custom entity and ral_product is the internal name. When running it i get "Error Occured". Any ideas what i did wrong?
Thanks!
*This post is locked for comments
Both solutions are supported.
It's my personal opinion but I use Chrome for everything including troubleshooting.
It worked ! Thanks a lot .
Two questions if you can please. Out of the two approaches (using SDK and using XRMServiceToolkit) which is the best way to do it? I mean are both solutions supported?
And lastly which browser you believe offers the best debugging tools for javascript with CRM?
Thanks again!
If ral_Cost is currency field that you should try something like:
alert(ral_product.ral_Cost.Value);
also you should learn how to troubleshoot code without alerts using browser debuggin tools - blogs.msdn.microsoft.com/.../debugging-custom-javascript-code-in-crm-using-browser-developer-tools
Thanks for the reply.
i have changed my code to this one:
function getCost() {
var product = Xrm.Page.data.entity.attributes.get("ral_product").getValue()[0];
alert("productid =" + product.id);
retrieveCost(product.id);
}
function retrieveCost(productId) {
SDK.REST.retrieveRecord(
productId,
"ral_product",
null, null,
function (ral_product)
{
testFunction(ral_product);
},
function () {
alert("Error Occured.");
}
);
}
function testFunction(ral_product) {
alert("success in testfunction");
alert(ral_product.ral_Cost);
}
Now it goes into testFunction , but i get alert popup [object] [object]
I have tried an alternative solution to use XRMServiceToolkit library and it does work great , however i'm a bit stubborn why the retrieveRecord function doesn't work.
Any ideas?
Hello,
You should not use Display Name in query. You should use Schema Name - ral_product but remember that it is case-sensitive.
I would suggest to use github.com/.../CRMRESTBuilder to prepare query and get initial version of code
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156