Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

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

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

  • e0209 Profile Picture
    e0209 45 on at
    RE: Attributes available in Xrm.Page.getControl().getGrid();

    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?

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Attributes available in Xrm.Page.getControl().getGrid();

    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);
                    }
                });
    
            }


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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans