Wednesday, August 7, 2024

Power Automate - Overwrite existing file in SP using create file control

if the file already exists at the target with the same name then the power automate will thorws an error. if the expectation is to overwrite the file in the target then a simple setting needs to be turned on in Sharepoint Create File control Turn Off Allow Chunking

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.

Friday, May 24, 2019

SDK: Create Email Using Template

        private static Guid CreateEmailMessageFromTemplate(IOrganizationService service, EntityReference contact, Guid templateId, EntityReference fromQueue)
        {
            InstantiateTemplateRequest request = new InstantiateTemplateRequest()

            {
                TemplateId = templateId,
                ObjectId = contact.Id,
                ObjectType = contact.LogicalName
            };
            InstantiateTemplateResponse response = (InstantiateTemplateResponse)service.Execute(request);
            Entity email = response.EntityCollection[0];
            var toActivityParty = new Entity("activityparty");
            toActivityParty["partyid"] = new EntityReference("contact", contact.Id);
            EntityCollection toParty = new EntityCollection() { EntityName = "activityparty" };
            toParty.Entities.Add(toActivityParty);

            var fromActivityParty = new Entity("activityparty");
            fromActivityParty["partyid"] = fromQueue;
            EntityCollection fromParty = new EntityCollection() { EntityName = "activityparty" };
            fromParty.Entities.Add(fromActivityParty);

            email.Attributes["to"] = toParty;
            email.Attributes["from"] = fromParty;
            return service.Create(email);
        }

Restrict Browser Back button

history.pushState(null, null, location.href);
    window.onpopstate = function () {
        history.go(1);
    };

Use the above code to restrict going to the back page from the current page.

This piece of code comes very handy when you are working on dynamics portals and you have logic where you should not allow users to navigate to back page.

Tuesday, October 23, 2018

D365 - Retreive more than 5000 records using fetchxml

 private static List RetrieveAllRecords(IOrganizationService service, string fetch)  
     {  
       var moreRecords = false;  
       int page = 1;  
       var cookie = string.Empty;  
       List<Entity> Entities = new List();  
       do  
       {  
         var xml = string.Format(fetch, cookie);  
         var collection = service.RetrieveMultiple(new FetchExpression(xml));  
         if (collection.Entities.Count >= 0) Entities.AddRange(collection.Entities);  
         moreRecords = collection.MoreRecords;  
         if (moreRecords)  
         {  
           page++;  
           cookie = string.Format("paging-cookie='{0}' page='{1}'", System.Security.SecurityElement.Escape(collection.PagingCookie), page);  
         }  
       } while (moreRecords);  
       return Entities;  
     }  

Usage

  var fetch = "<fetch {0}>" +  
             "  <entity name='accounts' >" +  
             "    <attribute name='accountid' />" +  
             "    <attribute name='name' />" +  
             "  </entity>" +  
             "</fetch>";  
       var accountCol = RetrieveAllRecords(service, fetch);