Skip to main content

Update using Pre and Post image into one field and get data from two fields?

 Code  inside Execute Functions in C#:


            // Extract the tracing service for use in debugging sandboxed plug-ins.


            ITracingService tracingService =


            (ITracingService)serviceProvider.GetService(typeof(ITracingService));



            // Obtain the execution context from the service provider.


            IPluginExecutionContext context =


            (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));



            // Obtain the organization service factory.


            IOrganizationServiceFactory serviceFactory =


            (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));



            // Obtain the organization service.    

            IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);



            if (context.InputParameters.Contains("Target") &&


                          context.InputParameters["Target"] is Entity)


            {


                // Obtain the target entity from the input parameters.


                Entity entity = (Entity)context.InputParameters["Target"];


                // User is updating only email address in lead form so we will get only 

               

        // get the lead email from context.


                string email = entity["emailaddress1"].ToString();


                // get the current record guid from context


                Guid leadRecordGuid = entity.Id;



                // Define variables to store Preimage and Postimage

                string pretopic = string.Empty; string posttopic = string.Empty; 


                // in below leadimage has been added in plugin registration tool


                // get PreImage from Context


                if (context.PreEntityImages.Contains("LeadTopicImage") && context.PreEntityImages["LeadTopicImage"] is Entity)

                {


                    Entity preMessageImage = (Entity)context.PreEntityImages["LeadTopicImage"];

                    // get topic field value before database update perform

                    pretopic = (String)preMessageImage.Attributes["subject"];


                }



                // get PostImage from Context

                if (context.PostEntityImages.Contains("LeadTopicImage") &&

                       context.PostEntityImages["LeadTopicImage"] is Entity)


                {


                    Entity postMessageImage = (Entity)context.PostEntityImages["LeadTopicImage"];


                    // get topic field value after database update performed

                    posttopic = (String)postMessageImage.Attributes["subject"];


                }



                // update the old and new values of topic field in description field


                Entity leadObj = new Entity("lead", context.PrimaryEntityId);

                //service.Retrieve(context.PrimaryEntityName, leadRecordGuid, new ColumnSet("description"));


                leadObj["description"] =

                "Pre-Image of description- " + pretopic + "   " + "Post-Image of description-- " + posttopic;


                service.Update(leadObj);


            }

Comments

Popular posts from this blog

Contacts View PCF Control

  1. Overview The ContactsControl component is a custom PowerApps control that displays a searchable and sortable table of contact records. It provides an interactive UI for filtering and selecting records. 2. Functionalities Search Feature: Allows users to filter records by entering text. Sorting: Clickable column headers enable ascending/descending sorting. Record Selection: Users can select a record to trigger a modal alert. Dynamic Rendering: Updates view dynamically based on search and sort input. Custom Styling: Uses external CSS for styling. 3. Component Structure Main Container ( HTMLDivElement ) : Holds the search bar and table. Search Input ( HTMLInputElement ) : Enables real-time search. Table ( HTMLTableElement ) : Displays the records with sortable headers. Modal Alert ( HTMLDivElement ) : Displays selected record details. 4. Implementation Details 4.1 Initialization ( init Method) Sets up the main container. Loads external styles. Creates...

Attachment PCF

Overview The AttachmentControl component is a PowerApps Component Framework (PCF) control designed for handling file uploads. It supports multiple file uploads, drag-and-drop functionality, file previews, and base64 encoding for easy data handling. Features Supports multiple file uploads Drag-and-drop functionality File type and size validation Base64 conversion for uploaded files Preview support for images, PDFs, and text files File removal functionality Code Breakdown Importing Dependencies import { IInputs, IOutputs } from "./generated/ManifestTypes"; The component imports IInputs and IOutputs from the generated manifest file to define the control's input and output types. Component Definition export class AttachmentControl implements ComponentFramework.StandardControl<IInputs, IOutputs> { Defines the AttachmentControl class, implementing the StandardControl interface from PCF. Class Variables private container: HTMLDivElement; private fileInput: HTMLInputEl...

Trigger JavaScript on Click of Button PCF Control

  Overview The TriggerJavascript control is a custom PCF (PowerApps Component Framework) control that renders a button with customizable label, icon, and on-click script execution. The control allows users to dynamically trigger JavaScript code upon clicking the button. Dependencies IInputs, IOutputs from ./generated/ManifestTypes (Auto-generated types from PowerApps) CSS styling from ./CSS/TriggerJavascript.css Class: TriggerJavascript This class implements ComponentFramework.StandardControl<IInputs, IOutputs> and manages rendering a button inside a container, dynamically executing JavaScript code on button click. Properties Private Properties _container: HTMLDivElement - A reference to the container element where the button will be rendered. Methods constructor() Initializes a new instance of the TriggerJavascript control. init(context: ComponentFramework.Context<IInputs>, notifyOutputChanged: () => void, state: ComponentFramework.Dictionary, container: HTMLD...