Hi everyone,
I am new to CRM 2011 and I want to write a Plugin that gets executed when a salesorder is created (post create).
I managed to access the information that is saved in the salesorder but I am running into problems when I try to access the, for example, the name of the related customer (accound entity). I already searched a while in this KB and tried several solutions but it did no work out :(
Here is my code:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Xrm.Sdk; using System.Runtime.Serialization; using System.IO; using Microsoft.Xrm.Sdk.Query; using Microsoft.Xrm.Sdk.Messages; namespace PluginTest { public class MyPluginTest: IPlugin { public void Execute(IServiceProvider serviceProvider) { // Obtain the execution context from the service provider. Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext) serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext)); // The InputParameters collection contains all the data passed in the message request. if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity salesOrder = (Entity)context.InputParameters["Target"]; if (salesOrder.LogicalName == "salesorder") { // Th customer ID: salesOrder["customerid"] //... How to get the customer name? } } } } }
How can I access the realted customer information? Thanks in advance!!