Posts

Difference Between Out parameters and REF parameters in C#

Image
In C#, both out and ref are used to pass arguments to methods by reference rather than by value. However, they have different behaviors: ref Parameter: The ref keyword is used to indicate that a parameter is passed by reference. When using ref, the variable must be initialized before it is passed to the method. This is because the method may read and modify the value of the variable, and it expects the variable to already have a value. Changes made to the parameter inside the method are reflected in the calling method's variable. Its Two way transmission Out Parameter: The out keyword is used to indicate that a parameter is passed by reference, but it does not require the variable to be initialized before it is passed to the method. Instead, it guarantees that the method will assign a value to the parameter before it returns. With out, the method is not required to read the initial value of the parameter; it can assign a new value to it. Changes made to the paramete...

How to Create a Business Process Flow and Get active stage of record and Update the Stage using C# in D365:

 Create a Business Process Flow                 Ex:  apy_ businessprocessflow           On Create of Contact record Create a business process flow and Get active stage and Set the Stage     Register Plugin on Create of Contact Entity                    using Microsoft.Xrm.Sdk;           using System;  namespace APY.Plugins.Sales {     public class ManageContact : IPlugin     {         public void Execute(IServiceProvider serviceProvider)         {             ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));             IPluginExecutionContext c...

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Connect D365 using below details: Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser Set-ExecutionPolicy –ExecutionPolicy RemoteSigned –Scope CurrentUser [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 $Username ="APY***@Trailcrm.com" $Password ="apy****" $pwd = ConvertTo-SecureString $Password -AsPlainText -Force  $credentials = New-Object System.Management.Automation.PSCredential($Username, $pwd) $conn = Connect-CrmOnline -Credential $credentials -ServerUrl "https://apytrailcrm****.crm.dynamics.com/" -ForceOAuth Create a record using powershell Syntax:     New-CrmRecord [-conn <CrmServiceClient>] [-EntityLogicalName] <String> [-Fields] <Hashtable> [<CommonParameters>] Ex:      $parentId = New-CrmRecord account @{"name"="parent account name"}     $parentReference = New-CrmEntityReference -EntityLogicalName account -Id $parentId     New-CrmRecord -conn ...

How to Create a Business Process Flow (BPF) on existing Contact and update the stage using conditions in D365 using Power Shell Script

 function UpdateProcessStage{ param( [int]$desiredStagePosition, $processInstance, $retrieveActivePathResponse ) $newStageId = $retrieveActivePathResponse.ProcessStages.Entities[$desiredStagePosition].Attributes["processstageid"] $entity = [Microsoft.Xrm.Sdk.Entity]::new("APY_"+$processInstance["name"].ToLower(), $processInstance.Id) $entity.Attributes.Add("activestageid", (New-CrmEntityReference -Id $newStageId -EntityLogicalName "processstage")) $CRMConnection.Update($entity) } function SetBPFToFinish{ param( $processInstance ) Set-CrmRecordState -conn $CRMConnection -EntityLogicalName APY_Purushflow -Id $processInstance.Id -StateCode 1 -StatusCode 2 } $conn = Get-CrmConnection -InteractiveMode $pagingCookie="" $page=1 $count=5000 do{     $varFetch = Get-CrmRecordsByFetch -conn $CRMConnection -Fetch @"    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="...

How to get more records using FetchXml with paging cookies using Power Shell Script

Connect D365 using below details:  $Username="APY***@Trailcrm.com" $Password="apy****" $pwd = ConvertTo-SecureString $Password -AsPlainText -Force  $credentials = New-Object System.Management.Automation.PSCredential($Username, $pwd) $CRMConnection = Connect-CrmOnline -Credential $credentials -ServerUrl "https://apytrailcrm****.crm.dynamics.com/" -ForceOAuth Declare variables: $pagingCookie="" $page=1 $count=5000 Using do while loop with FetchXml with below code will get more records do{     $varFetch = Get-CrmRecordsByFetch -conn $CRMConnection -Fetch @"    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">     <entity name="contact">     <attribute name="fullname" />     <attribute name="contactid" />     <order descending="false" attribute="fullname" />     <filter type="and...

How to connect d365 current using Powershell script.

 Install the "Microsoft.Xrm.Data.PowerShell" module: Open PowerShell and import the module with the following command if it's not already imported: Install-Module Microsoft.Xrm.Data.PowerShell -Scope CurrentUser There is a small issue with the command you provided. The correct parameter name for setting the execution policy is "ExecutionPolicy," not "–ExecutionPolicy."  Here's the correct version of the command: Set-ExecutionPolicy –ExecutionPolicy RemoteSigned –Scope CurrentUser The command you provided is used to set the security protocol used by .NET's ServicePointManager. Specifically, it sets the security protocol to TLS 1.2,  which is a more secure version of the TLS (Transport Layer Security) protocol used for secure communications over a computer network. [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 Define your CRM connection parameters: You'll need to gather some information to conne...

Get PartyList lookup field in Email/Activities entity update partyid record

Get the partylist lookup value and check the lookup value is contact and update the contact   Entity fromActivityParty = targetEntity.GetAttributeValue<EntityCollection>("from").Entities                 .Where(x => x.GetAttributeValue<EntityReference>("partyid")?.LogicalName == "contact")                 .FirstOrDefault();          if (fromActivityParty == null) return;          EntityReference contactReference = fromActivityParty.GetAttributeValue<EntityReference>("partyid"); Entity contact = new Entity("contact", contactReference.Id); contact["fullname"]= "ApyCRM"; service.Update(contact);