ComUnity Platform
25.x
25.x
  • ComUnity Technical Overview
  • Getting Started
    • ComUnity Developer Toolkit
      • Login
      • Manage your account: Profile, Settings, and Actions
    • Manage your project
      • Create a project
      • Project Settings
      • General
      • Build and launch your project
      • Templates
      • App Users & Roles
      • Themes
      • Versions
      • Icon Management
      • Store URLs
      • Deploy
        • Environments
        • Manual Project Deployment Across Environments
        • Configuration
    • Organisations
      • Roles and Permissions
      • Organisational Management
      • Teams
  • Toolkit Guides
    • Data
      • Customising the Data Model
      • Manage Entities in the Data Model: Step-by-Step Guide
      • Setting Up Role-Based Permissions for Entities: Access Control Configuration
      • Creating Entity Associations: Configuring Table Links
      • Manage Inheritance in the Data Model: Configuring Entity Hierarchy and Inheritance
    • Screens
      • Integrated Navigation and UI Builder for Screens in the ComUnity Developer Toolkit
      • Building Screens
        • Screen Controls
        • Navigation
          • Lists in Navigation pages
            • Dynamic List Rendering in Navigation pages
            • Adding Sub-Screens to Navigation pages Using List Navigation
          • Page Link
        • Form
          • Screen Controls
          • Lists in Form pages
            • Static Item - List Item
            • Single Item - List Item
            • Entity Items - List Item
    • Custom Classes
    • Custom Website
      • Bindings
      • Pages
        • Page Development
        • Page Elements
        • Templates
        • Resources
    • Communications
      • Configuring Dynamic Action Templates for Event-Driven Communication Channels
        • Event Details: Understanding Data Sources for Dynamic Template Building
        • Email
        • SMS & WhatsApp
        • INAPP
        • Push Notifications
        • HTTP
      • Triggering the Communication Service
      • Communication Settings
    • Events and Notifications Management
    • Observability
      • Client Analytics
      • Metrics
      • Traces
    • Third Party Services
      • Azure Function Apps
      • Azure Logic Apps
      • Integrations
      • Microsoft Fabric
      • APIs
    • Services
      • Media Server
  • General Information
    • Debugging and editing your application code
  • Toolkit Tutorials
    • Build a Simple Blog App: The Beginner's Guide to ComUnity Development
    • Building a Comprehensive News App: Integrating In-App Messaging, Push Notifications, SMS, and Email
    • APIs
      • JSON Placeholder Todos API Integration in a Simple Blog App
      • Countries GraphQL API Integration Using the APIs feature in the Toolkit
      • Integrating the JSONPlaceholder Posts API Using the Toolkit’s OpenAPI Feature
      • OData Integration with the Bookings API Using the APIs feature
    • How to Configure In-App Notifications for User Profile Updates Using Communications
  • Enhancing Cases App: Real-time Comment Notifications
  • Reference articles
    • Glossary
    • Privacy by Design
    • OData
    • Razor
    • CRUD Functions
    • Mustache Templating
    • Temporal Tables
    • Integrating WhatsApp Business with the ComUnity Platform
    • Data Types
    • Field Types
    • Table Links
    • Release Notes
    • Keyboard Shortcuts
Powered by GitBook
On this page
Export as PDF
  1. Toolkit Guides
  2. Communications

Triggering the Communication Service

Last updated 1 month ago

The CommsService.TriggerEvent() function has six required arguments which are outlined in the table below:

Argument
Type/Return Type
Description/Typical Value

appName

String

Config.AppName()

eventName

String

A unique name of your event defined under Configuration -> Communication Services

payload

JSON

Use the ComsServices.JsonSerialize() function to serialise the current instance of your class into JSON

url

String

Config.ComsService()

userName

String

Config.UserName()

password

String

Config.Password()

To trigger the Communication Service, follow these steps:

  1. Open your project and navigate to Data.

  2. Select Diagram or List to view your Data Model.

  3. Locate and select the entity for which you want to configure communications. In a Diagram view, click on the entity's header section with a grey background colour. An active entity is identified by a blue border, and none of its entity fields are active (active entity fields have a blue background colour).

  4. This action will open a properties dialog that displays the entity's global properties.

  5. Within the properties dialog, locate Custom Code you can expand the text editor by clicking on the icon.

  6. Now, you need to identify and select a change interceptor to initiate the ComsService.Trigger() function. If the custom code has already been auto-generated, you can proceed with selecting an appropriate change interceptor. However, if the custom code hasn't been auto-generated, you have the option to define your own partial class. Within this class, you can invoke the ComsService.Trigger() function using the interceptor of your choice as shown(check line 66 in the code block below):

// Copyright (c) ComUnity 2017

using ComUnity.DataServices;
using ComUnity.DataServices.DomainUtility.Exceptions;
using ComUnity.DataServices.DomainUtility.Security;
using ComUnity.DataServices.ServiceUtility;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.Services;
using System.Data.Services.Providers;
using System.Linq;
using System.Linq.Expressions;
using System.Web;

namespace CaseComms.Models
{
	public partial class Case
	{
		// START auto-generated - CTOR
		public Case() : base()
		{
		// END auto-generated, add custom code below this line
		
		}
		
		// START auto-generated - OnAdd
		public override void OnAdd(CaseCommsContext context)
		{
			base.OnAdd(context);
			CaseStatus status = context.Set<CaseStatus>().FirstOrDefault();
			Status = status ?? throw new GeneralException(400, "General", "No status defined in database!");
			context.SaveChanges();
			DateTime dt = DateTime.Now;
			string refString = dt.ToShortDateString() + "-" + CaseId;
			ReferenceNumber = refString;
			var toAddress = Config.CaseEmail();
			var an = Config.AppName();
			var cs = Config.ComsService();
			if (toAddress != null && an != null && cs != null)
			{
			    var payload = ComsServices.JsonSerialize(this);
			    ComsServices.TriggerEvent(an, "OnAddCase", payload, cs, Config.ComsServiceUsername(), Config.ComsServicePassword());
			}
		
		// END auto-generated, add custom code below this line
		
		}
		
		// START auto-generated - OnChange
		public override void OnChange(CaseCommsContext context)
		{
			base.OnChange(context);
			int prevStatus = context.Entry(this).OriginalValues.GetValue<int>("StatusCaseStatusId");
			if (StatusCaseStatusId != prevStatus)
			{
				var an = Config.AppName();
				var cs = Config.ComsService();
				if (an != null && cs != null)
				{
					var payload = ComsServices.JsonSerialize(this);
					// ComsServices.TriggerEvent() invocation
					ComsServices.TriggerEvent(an, "OnChangeCase", payload, cs, Config.ComsServiceUsername(), Config.ComsServicePassword());
				}
			}
		
		// END auto-generated, add custom code below this line
		
		}
		
		// START auto-generated - OnDelete
		public override void OnDelete(CaseCommsContext context)
		{
			base.OnDelete(context);
		// END auto-generated, add custom code below this line
		
		}
		
		// START auto-generated - Filter start
		public static Expression<Func<Case,bool>> Filter(CaseCommsContext context)
		{
			Expression<Func<Case, bool>> filter = o => true;
		// END auto-generated, add custom code below this line
			
		// START auto-generated - Filter end
			return filter;
		}
		// END auto-generated, add custom code below this line
		
		// START auto-generated - OnSeed
		public static void OnSeed(CaseCommsContext context)
		{
		// END auto-generated, add custom code below this line
		
		}
	}
}

After triggering the Communication Service by adding the code to invoke the ComsService.Trigger() function, the next step is to configure the event action and templates.