Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 46379

How to retrieve Account name on a plugin

$
0
0

This is my plugin code and I want desired requirement.

class AccountNamePlugIn : IPlugin
{
/// <summary>
/// A plug-in that auto generates an account number when an
/// account is created.
/// </summary>
/// <remarks>Register this plug-in on the Create message, account entity,
/// and pre-operation stage.
/// </remarks>
//<snippetAccountNumberPlugin2>
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)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
//</snippetAccountNumberPlugin2>

// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName == "salesorderdetail")
{
// An accountnumber attribute should not already exist because
// it is system generated.
if (entity.Attributes.Contains("new_axpaccountname") == false)
{
// Create a new accountnumber attribute, set its value, and add
// the attribute to the entity's attribute collection.

//I want here to retrieve name from account and assign it to salesorderdetail's, new_axpaccountname field //which is my custom field.

}
else
{
// Throw an error, because account numbers must be system generated.
// Throwing an InvalidPluginExecutionException will cause the error message
// to be displayed in a dialog of the Web application.
throw new InvalidPluginExecutionException("The account name can only be set by the system.");
}
}
}
}
}


Viewing all articles
Browse latest Browse all 46379

Trending Articles



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