Here we are populating fullname based on First Name and Last Name..
Rescource: https://learn.microsoft.com/en-us/power-apps/developer/data-platform/tutorial-write-plug-in
1) create class library
2) remane the plugin file name
3)copy namespaces (add this dll in references) and
class syntax from microsoft learn replace FollowupPlugin —> your plugin name
4)Add microsoft.sdx.dll reference in vs code ..where you downloaded in you laptop path
///— after comeplting code .. we need click on project then properites then click signing select checkbox sign
/// … click on new untick protect my key and enter keyfilename then save it
// build your code.. then go to file path open contaning folder..bin..debug..here you can see dll file after build
// copy that dll file path
// open plugin register tool and then click register .. register new assembly… paste the dll path.. click register selected plugins
//you can see your plugin now..click on that and then register new step
// in message add events … create..update ( based on requirement )
// in primary entity.. enter eniity that you wanted to trigger
// secondary entity is none
// in Filterting attribites… we can add specific fileds that we need to trigger ( helpul in update scenario )
// Select PreOperation.. click register new step
//This is original code for reference
using System;
using Microsoft.Xrm.Sdk;
namespace plugin1populatefullName
{
public class PopulateFullName : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the tracing service
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
// Obtain the execution context from the service provider.
IPluginExecutionContext context = (IPluginExecutionContext)
serviceProvider.GetService(typeof(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. --- Here in this object user entered data is saved
Entity sourceRecordInfo = (Entity)context.InputParameters["Target"];
// Obtain the IOrganizationService instance which you will need for
// web service calls.
IOrganizationServiceFactory serviceFactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
try
{
string firstName = " ";
string lastName = " ";
// Plug-in business logic goes here. //pass scheme name here
//----get syntax for plugin --single line filed
if (sourceRecordInfo.Contains("sdc_firstname") && sourceRecordInfo["sdc_firstname"] != null)
{
firstName = (string)sourceRecordInfo["sdc_firstname"];
}
//----get syntax for plugin --single line filed
if (sourceRecordInfo.Contains("sdc_lastname") && sourceRecordInfo["sdc_lastname"] != null)
{
lastName = (string)sourceRecordInfo["sdc_lastname"];
}
string fullname = firstName + " " + lastName;
//--set syntax for plugin --single line of syntax
sourceRecordInfo["crm_fullname"] = fullname;
}
catch (Exception ex)
{
//--add plugin class name here
tracingService.Trace("PopulateFullName: {0}", ex.ToString());
throw;
}
}
}
}
}