Home » Dynamics » Read Formatted values using LINQ Queries in Dynamics 365

Read Formatted values using LINQ Queries in Dynamics 365

Text Widget

This is a text widget. The Text Widget allows you to add text or HTML to your sidebar. You can use a text widget to display text, links, images, HTML, or a combination of these. Edit them in the Widget section of the Customizer.

Recently we had a business requirement where we came across an issue while retrieving formatted values using LINQ.

In this blog, we will discuss how to resolve this issue.

Suppose, we want to retrieve a revenue with currency symbol in the formatted value and we are using below query:

//Retrieve Account List with Name & Revenue
 var accountList = (from acc in _context.CreateQuery("account")
                      select new
                      {

                accName = acc.GetAttributeValue<string>("name"),

               revenue = acc.FormattedValues.Contains("revenue")? acc.FormattedValues["revenue"]: "No Data"

                                   }).ToList();

 It seems to be correct, but it fails to retrieve the revenue value with a currency symbol.

Instead, we were just getting “No Data” as the value which we have set if no revenue value found.

After some research and play around we found that the FormattedValues are not returned directly as shown above.

For that we needed to change the query to:

//Retrieve Account List with Name & Revenue
   var accountList = (from acc in _context.CreateQuery("account")
                        select new
                      {

                        accName = acc.GetAttributeValue<string>("name"),

              revenueField = acc.Attributes.Contains("revenue") ? acc["revenue"] : null,
         revenue = acc.FormattedValues.Contains("revenue") ? acc.FormattedValues["revenue"] : "No Data"

                                   }).ToList();

And then it worked!

Conclusion:

If we need to retrieve a Formattedvalue using LINQ, then we first need to read the attribute value, and then we may read the FormattedValues later in the query for that attribute.

from Microsoft Dynamics 365(CRM) Tips and Tricks http://bit.ly/2C0Gzi4
via IFTTT


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: