Показать сообщение отдельно
Старый 08.05.2009, 12:17   #21  
a33ik is offline
a33ik
Чайный пьяница
Аватар для a33ik
MCP
MCBMSS
Злыдни
Соотечественники
Most Valuable Professional
Лучший по профессии 2017
Лучший по профессии 2015
Лучший по профессии 2014
Лучший по профессии AXAWARD 2013
Лучший по профессии 2011
Лучший по профессии 2009
 
3,243 / 896 (36) +++++++
Регистрация: 02.07.2008
Адрес: Greenville, SC
Lightbulb
Подчистил код плагина. Попробуйте это:

Код:
using System;
using System.Collections.Generic;
using Microsoft.Win32;
using Microsoft.Crm.Sdk.Query;
// Microsoft Dynamics CRM namespaces
using Microsoft.Crm.Sdk;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.SdkTypeProxy.Metadata;
using System.Text;
namespace Crm.Plugins
{
    public class MyPlugin : IPlugin
    {
        private string _secureInformation;
        private string _unsecureInformation;
        public MyPlugin(string unsecureInfo, string secureInfo)
        {
            _secureInformation = secureInfo;
            _unsecureInformation = unsecureInfo;
        }
        public void Execute(IPluginExecutionContext context)
        {
            DynamicEntity entity = null;
            if (context.InputParameters.Properties.Contains(ParameterName.Target) && context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
            {
                entity = (DynamicEntity)context.InputParameters.Properties[ParameterName.Target];
            }
            else
            {
                return;
            }

            try
            {
                ICrmService crmService = context.CreateCrmService(true);

                decimal sum = ((CrmMoney)entity.Properties["new_esum"]).Value;
                String new_productname = "";

                if (entity.Properties.Contains("productid"))
                {
                    ColumnSet cs = new ColumnSet();
                    Lookup regarding = (Lookup)entity.Properties["productid"];
                    cs.Attributes.Add("name");
                    product _product = (product)crmService.Retrieve(EntityName.product.ToString(), regarding.Value, cs);
                    if (_product == null || _product.name == null)
                    {
                        return;
                    }
                    else
                    {
                        new_productname = _product.name;
                    }
                }

                QueryByAttribute query = new QueryByAttribute();
                query.ColumnSet = new AllColumns();
                query.EntityName = EntityName.productpricelevel.ToString();
                query.Attributes = new string[] { "productidname" };
                query.Values = new string[] { new_productname };

                BusinessEntityCollection retrieved = crmService.RetrieveMultiple(query);

                foreach (DynamicEntity product in retrieved.BusinessEntities)
                {
                    product["amount"] = new CrmDecimal(sum);
                    crmService.Update(product);
                }
            }
            catch (System.Web.Services.Protocols.SoapException ex)
            {
                throw new InvalidPluginExecutionException(String.Format("An error occurred in the {0} plug-in.", this.GetType().ToString()), ex);
            }
        }
    }
}
__________________
Эмо разработчик, сначала пишу код, потом плачу над его несовершенством.

Подписывайтесь на мой блог, twitter и YouTube канал.
Пользуйтесь моим Ultimate Workflow Toolkit