web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Get Attribute from related entity using Javascript

(0) ShareShare
ReportReport
Posted on by

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:

6406.Screenshot.png

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.

https://blogs.msdn.microsoft.com/emeadcrmsupport/2015/09/24/dynamics-crm-how-to-access-a-quickform-component-via-jscript-in-turbo-forms/

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

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

  • Community Member Profile Picture
    on at

    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?

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    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

  • Community Member Profile Picture
    on at

    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!

  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Both solutions are supported.

    It's my personal opinion but I use Chrome for everything including troubleshooting.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans