Thursday, January 12, 2023

D365 Clear Power Apps Portal Cache

 In Dynamics 365 Power Apps portals, you can clear the cache of the portal using the PortalCacheService class. The PortalCacheService class provides methods to clear the cache for specific entities or for the entire portal.

Here is an example of how you might use C# code to clear the cache for a specific entity in a Dynamics 365 Power Apps portal:


using Microsoft.PowerApps.Portals; // ... public void ClearCacheForEntity(string entityName) { var cacheService = new PortalCacheService(); cacheService.ClearCacheForEntity(entityName); }

And here's how you can clear the entire portal cache:

using Microsoft.PowerApps.Portals; // ... public void ClearAllCache() { var cacheService = new PortalCacheService(); cacheService.ClearAllCache(); }

You can call above methods wherever you want to clear the cache, like in a button click event or on some specific conditions.

Please note that, this code sample is for the portal which is build using Power App portals, if you are using Dynamics 365 portals, the approach will be different. Also, keep in mind that clearing the cache can cause a temporary performance hit on the portal, so it is generally a good idea to clear the cache during off-peak hours or when the portal is not heavily used.

Update content setting in live customer journey in d365 marketing

 In Dynamics 365 Marketing, you can use the Live Customer Journey feature to update the content of an active customer journey while it is running. This allows you to make changes to the journey without having to stop and restart it, which can save time and minimize disruption to your customers.

Here is an example of how you might update the content of an active customer journey using the Dynamics 365 Marketing API

// Update the content of an active customer journey function updateContentSetting(customerJourneyId: string, contentSettingId: string) { // Update the content setting var update = { content: "<p>New Content</p>" }; var req = new XMLHttpRequest(); req.open("PATCH", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/marketing/customerjourneys(" + customerJourneyId + ")/Microsoft.Dynamics.Marketing.LiveCustomerJourney/contentSettings("+contentSettingId+")", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 204) { // Content setting updated successfully console.log("Content setting updated successfully"); } else { console.log(this.statusText); } } }; req.send(JSON.stringify(update)); }


In this sample, you pass the customerJourneyId and contentSettingId of the customer journey to update and it will update the content of the customer journey. This is a simplified example you may need to import the required types and configure the appropriate options as per your need.

Please note that in order to use this sample code, you must have the appropriate permissions to update customer journeys in Dynamics 365 Marketing, and you must have an active customer journey with a content setting that you want to update.

Also, keep in mind that modifying an active customer journey can impact the ongoing customer interactions and cause unexpected results, so be sure to thoroughly test any changes you make before applying them to a live customer journey.

Create and Send SMS in D365 Marketing

 In Dynamics 365 Marketing, you can use the SMS message type to create and send SMS messages to contacts or leads in your database. The process for creating and sending an SMS message involves several steps:

  1. Create an SMS message template: In Marketing, navigate to Email and SMS > SMS message templates, and create a new template. In the template, you can specify the message content, and include personalization fields to dynamically insert information from the contact or lead record.

  2. Create an SMS message: In Marketing, navigate to Email and SMS > SMS messages, and create a new message. In the message, you can specify the recipient list, select the SMS message template, and set the send options.

  3. Send the SMS message: After creating the SMS message, you can send it immediately or schedule it to be sent at a later time.

Here's a sample process on how to send SMS message by using a sample code

var smsMessage = { recipientList: { query: "contacts", filter: "statuscode eq 1" }, template: { id: "cf5b5f0f-cbc4-45c9-9edf-e8a0da22b2d4" }, sender: { id: "c1b5f0f-cbc4-45c9-9edf-e8a0da22b2d3" }, sendImmediately: true }; var smsMessageId = Xrm.WebApi.createRecord("sms", smsMessage).then( function success(result) { var smsId = result.id; console.log("SMS created with ID: " + smsId); }, function (error) { console.log(error.message); });

This is just a simplified example, in your real scenario you may have to customize it as per your need, like you may have to import required types and apply the appropriate configurations options. Please note that in order to use this sample code, you must have the appropriate permissions to create and send SMS messages in Dynamics 365 Marketing, and you must have an active SMS message template and SMS sender account set up in your system.

Please be aware that SMS messaging is generally regulated, and laws and regulations vary by country. Before sending SMS messages to contacts or leads, you should familiarize yourself with any relevant laws and regulations, and obtain any necessary consent from your contacts or leads.