Posts

Showing posts from August, 2023

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