Professional Documents
Culture Documents
Create A Task After Account Creation ?
Create A Task After Account Creation ?
1. Delete the class library and add new class with name Create task after
account creation.
2. Add References System.Runtime.Serialization And Microsoft.Xrm.Sdk.dll
namespace Create_a_task_after_account_creation
{
public class Create_Task_After_Creation : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
if (context.OutputParameters.Contains("id"))
{
Guid regardingobjectId = new Guid(context.OutputParameters["id"].ToString());//GUID
}
}
catch (Exception ex)
{
}
return crmService.Create(followup);
}
}
}
1. Sign in And Build. Open File explorer And Take dll Project.
2. Register Plugin
Update a child records(Contact) via Fetch Xml In Account Entity
Create a Company and city column by using advance find. Update Siva Reddy and
Neelavathi City as Banglore.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace Contact_update_via_Fetch_Xml_In_Account
{
public class Contact_Update_via_fetch_Xml_in_Account : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
if (accountId != Guid.Empty)
{
EntityCollection contactRecords = getAllRelatedContacts(accountId, service);
{
foreach (Entity contact in contactRecords.Entities)
{
contact["firstname"] = "Bhargav";
contact["lastname"] = Name;//A. Datum
service.Update(contact);
}
}
}
}
}
catch (Exception ex)
{
}
return contacts;
}
}
PLUGIN DEBUGER
Trigger The Function in Dynamics 365
Copy The Log file and past it into the Plugin Dll
Getting Primary Contact ID and Name Then Job Title
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace GettingPrimaryContactIDandNamethenJobTitle
{
public class GettingPrimaryTitle : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName != "account")
return;
Guid AccountID = context.PrimaryEntityId; // accoutID
}
}
catch (Exception ex)
{
}
}
public Guid createEntityRecord(string entityName, EntityReference regardingObject,
IOrganizationService crmService, string title)
{
// Create a task activity to follow up with the account customer in 7 days.
Entity followup = new Entity(entityName);//task
followup["subject"] = title;
followup["description"] = "Follow up with the customer. Check if there are any new issues that
need resolution.";
followup["scheduledstart"] = DateTime.Now.AddDays(7);
followup["scheduledend"] = DateTime.Now.AddDays(7);
followup["category"] = regardingObject.LogicalName;//account
followup["regardingobjectid"] = regardingObject; // account gUID
return crmService.Create(followup);
}
Query By Attribute
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace Update_Purchasing_Assistant_With_Title_Name_Developer_with_QA
{
public class Update_Developer_with_Query_Attribute : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Extract the tracing service for use in debugging sandboxed plug-ins.
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));
try
{
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
if (context.Depth == 1)
{
foreach (Entity contact in results.Entities)
{
contact["telephone1"] = " Purchasing officer";
service.Update(contact);
}
}
}
}
catch (Exception ex)
{
}
}
}
}