Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM Plugin - doesn't appear to do anything

$
0
0

I have written my first plug-in, but it doesn't appear to do anything.

I have a field on the quote form that I want updating with the parentproduct names from the products that are on the quote when the quote is activated, here is the code:

namespace Plugin_Project
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xrm.Sdk;
    using System.ServiceModel;
    using System.Threading.Tasks;
    using Microsoft.Xrm.Sdk.Query;

    public class PreQuoteUpdate: Plugin
    {

        public PreQuoteUpdate()
            : base(typeof(PreQuoteUpdate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(20, "Update", "quote", new Action<LocalPluginContext>(ExecutePreQuoteUpdate)));

        }

        protected void ExecutePreQuoteUpdate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            ITracingService tracingService = localContext.TracingService;
            IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)localContext.ServiceProvider.GetService(typeof(IOrganizationServiceFactory));

            Entity entity = null;

                // linq QUERY
                Quote currentQuote = entity.ToEntity<Quote>();
                using (GeneratedCode orgcontext = new GeneratedCode(service))
                {
                    var _results = (from quote in orgcontext.QuoteSet
                                    join qd in orgcontext.QuoteDetailSet on quote.QuoteId equals qd.QuoteId.Id
                                    join prod in orgcontext.ProductSet on qd.sp_SellingProductId.Id equals prod.ProductId
                                    where (quote.Name == "QUO-01694-D9H2")
                                    select prod.orb_ParentProductid).Distinct();

                    var _txttowrite = "";
                    foreach (var x in _results)
                    {
                        _txttowrite = x + ", ";
                    }

                    currentQuote.ancon_quoteproducts = _txttowrite;
                }
        }
    }
}

For testing purposes I have got it to look up the products on one specific quote.

I am new to this plugin development so struggling a little.

regards,

Matt


Viewing all articles
Browse latest Browse all 8223

Trending Articles



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