Quantcast
Channel: Forum CRM Development
Viewing all articles
Browse latest Browse all 1000

Fetch XML V LINQ

$
0
0

I wrote a plugin that appeared to work as it should, the only issue is when there are nulls in the returned data the code errors:

using (GeneratedCode orgcontext = new GeneratedCode(service))
                    {

                        var retrievedProducts = (from p in orgcontext.ProductSet
                                                 join qd in orgcontext.QuoteDetailSet
                                                 on p.ProductId equals qd.sp_SellingProductId.Id
                                                 where qd.QuoteId.Id == entity.Id                                                 
                                                 select new
                                                 {
                                                     product_name = p.orb_ParentProductid.Name
                                                 }).Distinct();


                        var _txttowrite = string.Empty;
                        if (retrievedProducts != null)
                        {
                            // for each item returned write the output to a string.

                            foreach (var item in retrievedProducts)
                            {
                                if (item.product_name != "")
                                {
                                    if (String.IsNullOrEmpty(_txttowrite))
                                    {
                                        _txttowrite = item.product_name;
                                    }
                                    else
                                    {
                                        _txttowrite += ", " + item.product_name;
                                    }
                                }
                            }


                        }

Now as I have been struggling to get this working I constructed a similar query in FetchXML, which dealt with the null values and outputted the results:

<?xml version="1.0"?>

-<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">


-<entity name="quotedetail"><attribute name="quotedetailid"/>


-<link-entity name="quote" alias="ab" to="quoteid" from="quoteid">


-<filter type="and"><condition value="QUO-02095-L7W6" operator="eq" attribute="name"/><condition value="10" operator="eq" attribute="revisionnumber"/></filter></link-entity>


-<link-entity name="product" alias="a_cf8cac3f6909e211a4d002bf0a86f1e1" to="sp_sellingproductid" from="productid"><attribute name="orb_parentproductid"/>


-<filter type="and"><condition operator="not-null" attribute="orb_parentproductid"/></filter></link-entity></entity></fetch>

The issue with the fetchXML is that it is tied into a single quote and revision, how can I get it to work with the current quote i.e. make it dynamic?

The second question is I want to pass the retrieved parentproduct out to a text field how do I get access to this?  must admit I am getting myself confused with all this.

any help appreciated.

Matt


Viewing all articles
Browse latest Browse all 1000

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>