Показать сообщение отдельно
Старый 25.02.2009, 12:13   #15  
Bondonello is offline
Bondonello
Kostya Afendikov
Аватар для Bondonello
MCBMSS
Лучший по профессии 2009
 
510 / 106 (5) +++++
Регистрация: 06.06.2008
Адрес: Украина
Я немного не разобрался с Image пока что, и сделал вот так. Возможно кому-то пригодиться
Регистрирую на Create и Update + Pre Stage.
А вот с Image разбираюсь
X++:
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];

                if (context.MessageName != MessageName.Update.ToString()
                    && context.MessageName != MessageName.Create.ToString())
                {
                    throw new InvalidPluginExecutionException("Smth wrong with Update stage may be");
                }
            }
            else
            {
                return;
            }

            try
            {
                
                ICrmService crmService = context.CreateCrmService(false);
                    if(entity.Properties.Contains("regardingobjectid"))
                    {
                        String do_companyname = "";
                        ColumnSet cs = new ColumnSet();
                        Lookup regarding = (Lookup)entity.Properties["regardingobjectid"];
                        
                            // проверяю, что в лукапе выбран Интерес
                            if (regarding.type == EntityName.lead.ToString())
                            {
                                cs.Attributes.Add("companyname");
                                lead _lead = (lead)crmService.Retrieve(EntityName.lead.ToString(), regarding.Value, cs);
                                if (_lead == null ||
                                    _lead.companyname == null)
                                {
                                    return;
                                }
                                else
                                {
                                    new_companyname = _lead.companyname;
                                }
                            }
                        


                        entity.Properties.Add(new StringProperty("new_companyname", new_companyname));
                    }
                }