6. September 2010 14:55
if (properties.Contains("originatingleadid"))
public class Lead2Opportunity : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
# region Allgemeines
/* Umweg über DynamicEntity und TargetUpdateDynamic, so kann ein PropertyCollection.Contains(...) losgetreten werden,
* das im Gegensatz zu entity.property == null keine Exeption schmeißt!
* Nachteil: man kann nicht per Intellisense die Attribute der Entität auswählen...
*/
Microsoft.Crm.Sdk.DynamicEntity target = (Microsoft.Crm.Sdk.DynamicEntity)context.InputParameters[ParameterName.Target];
TargetUpdateDynamic update = new TargetUpdateDynamic();
update.Entity = target;
PropertyCollection properties = update.Entity.Properties;
# endregion
if (properties.Contains("originatingleadid"))
{
#region getLead
lead leadEntity = null;
ICrmService service = null;
try
{
Guid leadid = ((Lookup)target["originatingleadid"]).Value;
service = context.CreateCrmService(true);
TargetRetrieveLead retrieve = new TargetRetrieveLead();
retrieve.EntityId = leadid;
RetrieveRequest request = new RetrieveRequest();
request.Target = retrieve;
request.ColumnSet = new Microsoft.Crm.Sdk.Query.AllColumns();
RetrieveResponse response = (RetrieveResponse)service.Execute(request);
BusinessEntity businessEntity = response.BusinessEntity;
leadEntity = (lead)businessEntity;
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
#endregion getLead
throw new InvalidPluginExecutionException(leadEntity.leadid.Value.ToString());
}
else
{
throw new InvalidPluginExecutionException("nur neu");
}
}
9. September 2010 10:46
9. September 2010 10:58