Пишу плагин первый раз. Задача следующая: при создании product создавать и прикреплять productpricelevel
Код такой
Код:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using System.Text;
using SDK = Microsoft.Crm.Sdk;
using SDKType = Microsoft.Crm.SdkTypeProxy;
using Prodd.CrmSdk;
namespace Prodd
{
public class Class1 : SDK::IPlugin
{
public void Execute(SDK::IPluginExecutionContext context)
{
XmlDocument xmlConfig = new XmlDocument();
xmlConfig.Load(@"C:\WIN2003\system32\inetsrv\PluginsConfig.xml");
XmlNode rootConfig = xmlConfig.FirstChild;
string serverName = rootConfig["server"].InnerText;
string orgName = rootConfig["organization"].InnerText;
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = 0;
token.OrganizationName = orgName;
CrmService service = new CrmService();
service.Url = "http://" + serverName + "/mscrmservices/2007/CrmService.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
//-----------------------------------------------------------------------------------------
SDK::DynamicEntity currentPrice = context.PostEntityImages["Prod"] as SDK::DynamicEntity;
// Продукт
Lookup lookupProduct = new Lookup();
lookupProduct.Value = ((SDK::Lookup)currentPrice.Properties["productid"]).Value;
// Прайс-лист
Lookup lookupPrice = new Lookup();
lookupPrice.Value = ((SDK::Lookup)currentPrice.Properties["pricelevelid"]).Value;
// Единица измерения
Lookup lookupUom = new Lookup();
lookupUom.Value = ((SDK::Lookup)currentPrice.Properties["defaultuomscheduleid"]).Value;
decimal price = ((SDK::CrmMoney)currentPrice.Properties["price"]).Value;
if (((SDK::CrmMoney)currentPrice.Properties["price"]) == null)
price = 0;
//создаем прайс-лист
productpricelevel bePriceUpdate = new productpricelevel();
bePriceUpdate.amount.Value = price;
bePriceUpdate.productid = lookupProduct;
bePriceUpdate.pricelevelid = lookupPrice;
bePriceUpdate.uomid = lookupUom;
service.Create((BusinessEntity)bePriceUpdate);
}
}
}
PostEntityImages["Prod"] слепок данных в plugin registration tool.
Там выбираю соответственно: productid, pricelevelid, defaultuomscheduleid, price.
В таком виде плагин не работает, возможно проблема в decimal price...
Подскажите, если ошибка очевидна, пожалуйста.
PluginsConfig.xml:
Код:
<config>
<server>crm</server>
<organization>Company</organization>
</config>