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)

Attributes available in Xrm.Page.getControl().getGrid();

(0) ShareShare
ReportReport
Posted on by 45

Hi,

When I use the below function to get the attributes in a grid (showing opportunityproducts records) from the opportunity, the attributes returned are missing some of the fields available in Opportunity Product entity. 

Why is this so and how can I get those fields to be returned?

function getGridData() {

var grid = Xrm.Page.getControl("Product_Line").getGrid();
var rows = grid.getRows();
var rowList = [];
var j = 0;

rows.forEach(function (row, index)
	{
		try
		{
			var data = row.getData();
			var crmEntity = data.getEntity();
			var attributes = crmEntity.getAttributes().getAll();
			attributes.forEach(function (attribute, index)
			{
				try
				{

                                  console.log("Name: " + attribute.getName());
                                  console.log("Value: " + attribute.getValue());


				}
				catch (e)
				{
					console.error(e);
				}
			});
		}
		catch (e)
		{
			console.error(e);
		}
	});


}


Thanks!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    Hi ,

    Try with this  by giving field name -

            function getGridData() {
    
                var grid = Xrm.Page.getControl("Product_Line").getGrid();
                var rows = grid.getRows();
                var rowList = [];
                var j = 0;
    
                rows.forEach(function (row, index) {
                    try {
                        var data = row.getData();
                        var crmEntity = data.getEntity();
                        var attributes = crmEntity.getAttributes();
                        var value = attributes.get("FieldName").getValue(); //Replace field name 
                        //var attributes = crmEntity.getAttributes().getAll();
                        //attributes.forEach(function (attribute, index) {
                        //    try {
                        //        console.log("Name: " + attribute.getName());
                        //        console.log("Value: " + attribute.getValue());
                        //    }
                        //    catch (e) {
                        //        console.error(e);
                        //    }
                        //});
                    }
                    catch (e) {
                        console.error(e);
                    }
                });
    
            }


  • e0209 Profile Picture
    45 on at

    Hi Goutam, 

    Thanks for your suggestion.

    I have tried that, replacing "FieldName" with my Field Name but it does not seem to find my field, gives an error:

    TypeError: Cannot read property 'getValue' of null

    The field names I have tried exists within Customizations -> Opportunity Products -> Fields in the Name/Schema Name columns. It is of a Simple type.

    It is also weird that with the crmEntity.getAttributes().getAll(), the attributes that are returned do not have the exact name as the field names in Opportunity Product.

    For example the attribute returned by the getAll() function is 'priceperunit_rawvalue' while in Opportunity Products it is just 'priceperunit'.

    Have you come across this behavior before?

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