We will enable the In-app notification features in the model-driven app and implement a plugin code to retrieve the messages.
- Sign in to https://make.powerapps.com/
- Open the solution that contains the model-driven app.
- Select the model–driven app and select the edit.
Write a plugin to get a notification when a new case is created in the customer service workspace.
Open Visual Studio and select Create a new project.
Search for the class library, select the Class Library (.Net Framework), and click on Next.
Give the project name, select the latest .Net framework, and click on Create.
To install CRM Core Assemblies right right-click on solution, select Manage NuGet packages as shown in the below screen, and search for Microsoft.CRMSdk.CoreAssemblies and install it.
Next to install the plugin registration tool in the solution right-click on the solution once again, select Manage NuGet packages as shown in the below screen, and search for Microsoft.CRMSdk.XrmTooling.PluginRegistrationTool and install it.
The below references will be added to the solution once we install both packages.
Next, Update the below code in Class1.cs and build the solution.
using Microsoft.Xrm.Sdk;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Threading.Tasks;
namespace InApp_Notofication_Demo
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "incident")
{
return;
}
if (context.MessageName == "Create")
{
var request = new OrganizationRequest()
{
RequestName = "SendAppNotification",
Parameters = new ParameterCollection
{
["Title"] = "A New Case has been Created",
["Recipient"] = entity.GetAttributeValue<EntityReference>("ownerid"),
["Body"] = "A new Case has been created you.",
["Expiry"] = 1209600,
["Actions"] = new Entity()
{
Attributes = new AttributeCollection()
{
["actions"] = new EntityCollection()
{
Entities = new List<Entity>()
{
new Entity()
{
Attributes = new AttributeCollection()
{
["title"] = "Open Case",
["data"] = new Entity()
{
Attributes = new AttributeCollection()
{
["type"] = "url",
["url"] = $"?pagetype=entityrecord&etn={entity.LogicalName}&id={entity.Id}",
["navigationTarget"] = "newWindow"
}
}
}
}
}
}
}
}
}
};
service.Execute(request);
}
}
}
}
Next, open the plugin registration tool to register your plugin, once tool get open click on the Create New Connection button, a new window will open there please select Display list of available originations and show the advanced check box, and enter the user id and password as shown in below screen.
Select your environment for list options and click on login.
Once the tool is open click on register, select register New Assembly, and show in the below screen.
A new window will open, select our DLL from Load Assembly. And click on the register selected plugin.
Once the plugin is registered, right-click on that and select Register New Step.
Select the Message as “Create” and the Primary Entity as “incident”.
Select the execution stage as “PostOperation” as shown below screen.
Finally, Navigate to CRM customer service workspace and create new cases in CRM.
Once is new case is created in CRM notification message is received in the notification section as shown below screen.