Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM 2011 Retrieve related entity information, Post create salesorder, access related customer (account) entity

$
0
0

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!!


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>