Skip to content
This repository has been archived by the owner on Jan 29, 2022. It is now read-only.

Dataverse Powershell Library v2.1.1.0

Compare
Choose a tag to compare
@AMSoftwareNL AMSoftwareNL released this 06 Aug 13:06
· 4 commits to master since this release

Issues & Changes

  • #26 Support Batch operations

  • #28 Get and Set Environment Variables

  • #30 Service Endpoint doesn't support Webhook and EventHub

  • #31 Support for Virtual Entities and custom data-sources

  • #33 Provide clear error info when connection fails (see also #32)

  • #34 Support new multi-table lookup

  • #35 Support Upsert

  • Update to latest supported framework and packages

    • Microsoft.CrmSdk.XrmTooling.CoreAssembly 9.1.0.79

Polymorphic (Multi Table) Lookup

Add a Polymorphic Lookup the same way a normal lookup is added, just add the switch Polymorphic. Add one single relationship at a time. When the relationship/lookup is marked as Polymorphic The Lookup and Relationship are created if the Attribute doesn't exist. Else the Relationships is added to the exiting Lookup. In this case additional Attribute parameters are ignored.

Microsoft documentation: Use multi-table lookup columns

Add-CrmRelationship -Entity 'new_media' -ToEntity 'new_books' -Name 'new_media_books' -Polymorphic -AttributeName 'new_contentid' -AttributeDisplayName 'Content'
Add-CrmRelationship -Entity 'new_media' -ToEntity 'new_audio' -Name 'new_media_audio' -Polymorphic -AttributeName 'new_contentid' -AttributeDisplayName 'Content' -
Add-CrmRelationship -Entity 'new_media' -ToEntity 'new_video' -Name 'new_media_video' -Polymorphic -AttributeName 'new_contentid' -AttributeDisplayName 'Content'

Data Providers, Data Sources and Virtual Tables

Register Data Providers, and create Data Source Tables and Virtual Tables.

Microsoft documentation: Get started with virtual tables

$publisher = New-CrmPublisher -Name 'amsoftware_test' -DisplayName 'AMSoftware (Test)' -Prefix 'ams' -PassThru
$solution = New-CrmSolution -Name 'ams_virtual_data' -DisplayName 'Virtual Data' -Version '1.0.0.0' -Publisher $publisher -PassThru
Use-CrmSolution $solution

$plugin = Register-CrmPlugin -LiteralPath '.\DSPlugin.dll' -IsolationMode Sandbox -AssemblyLocation Database -PassThru

# Create the Data Source Virtual Table to hold the actual Data Sources (configurations)
New-CrmEntity -DataSource -Name 'ams_rssfeed' -DisplayName 'RSS Feed Data Source' -DisplayCollectionName 'RSS Feed Data Sources' -AttributeName 'ams_name' -AttributeDisplayName 'Name' -AttributeExternalName 'name' -AttributeRequired Required -PassThru
Add-CrmStringAttribute -Entity 'ams_rssfeed' -Name 'ams_feeduri' -Format Url -Length 250 -DisplayName 'Feed URI' -Required Required -ExternalName 'feeduri'
Add-CrmStringAttribute -Entity 'ams_rssfeed' -Name 'ams_feedkey' -Format Url -Length 25 -DisplayName 'Feed Key' -Required Required -ExternalName 'feedkey' -IsDataSourceSecret

# Add a Data Source Configuration. The ID is needed for creation of the Virtual Table
$feedconfig = Add-CrmContent -Entity 'ams_rssfeed' -Attributes @{ams_name='Microsoft Power Platform Blog';ams_feeduri='https://cloudblogs.microsoft.com/powerplatform/feed/';ams_feedkey='secret'} -PassThru

# Register the Data Provider with the Data Source
$dataprovider = Register-CrmDataProvider -Name 'RSS Feed Data Provider' -DataSourceLogicalName 'ams_rssfeed' -RetrievePlugin $plugin -RetrieveMultiplePlugin $plugin -CreatePlugin $plugin -UpdatePlugin $plugin -DeletePlugin $plugin -PassThru

# Create the Virtual Table to hold the 'Microsoft Power Platform Blog' feed
New-CrmEntity -Virtual -Name 'ams_powerplatformblogfeed' -DisplayName 'Microsoft Power Platform Blog' -DisplayCollectionName 'Microsoft Power Platform Blogs' -ExternalName 'powerplatformblogfeed' -ExternalCollectionName 'powerplatformblogfeeds' -DataSourceConfiguration $feedconfig.ToEntityReference() -AttributeName 'ams_title' -AttributeDisplayName 'Title' -AttributeExternalName 'title' -AttributeRequired Required -AttributeLength 255 -HasNotes $true

Environment Variables

Define Environment Variables and set the Value.

Microsoft documentation: Environment variables overview

Service Endpoints, Webhooks and EventHub

Registration of Service Endpoints is updated to the latest configuration options, and now also supports registration for Azure EventHub.

The registration of WebHooks is added using Register_CrmWebHook

Microsoft Documentation:
Use WebHooks to create external handlers for server events
Work with Microsoft Dataverse event data in your Azure Event Hub solution

Upsert instead of just Add

On Add-Content include the Upsert switch to perform an Upsert instead of an Add.

Microsoft documentation: Use Upsert to insert or update a record

Batch support

For the more exotic scenarios simple batched operations can now be performed based on the ExecuteMultiple request and the ExecuteTransaction request. Only a simple batch is a supported. No nesting or multiple transaction, and the whole batch is a transaction or not.

Only the default content cmdlets can be include in a batch by adding the AsBatch switch.

  • Add-CrmContent
  • Get-CrmContent
  • Join-CrmContent
  • Remove-CrmContent
  • Set-CrmContent
  • Split-CrmContent
  • Invoke-CrmRequest
Start-CrmBatch
Add-CrmContent -Entity 'account' -Attributes @{name='Account 1'} -AsBatch
Add-CrmContent -Entity 'account' -Attributes @{name='Account 2'} -AsBatch
Add-CrmContent -Entity 'account' -Attributes @{name='Account 3'} -AsBatch
Add-CrmContent -Entity 'account' -Attributes @{name='Account 4'} -AsBatch
Submit-CrmBatch -AsTransaction -ReturnResponses

Retrieve Data Performance

There was a major issue with the performance when getting data. Getting 50 rows of data took almost 30 seconds. This was due to a major issue in the EntityPropertyAdapter. This adapter does the flattening/pivoting of the Attributes-collection and FormattedValues-collection. For every row multiple calls to the Entity- and Attribute-metadata were performed. This is now solved by getting the metadata for the Entity and Attributes once and using this.
In addition the Metadata-cache was checked on every call to metadata. Now the cache is checked (and updated if needed) at the start of every cmdlet (in the BeginProcessing function), so during execution of the cmdlet the up-to-date cache is used, and no longer being checked or updated.

Fixes, Optimizations and Performance improvements

  • Dynamic Parameters merged with normal cmdlet logic
    No more use of Dynamic Parameters based on versions as this wasn't updated since Dynamics 2016. Dynamic Parameters were also not included in the docs. Now the docs are complete.
  • Removed VersionChecks
    Version checks on cmdlets and parameters are removed. Every cmdlet is now always up-to-date with the latest version of Dataverse. It's up to the user to skip non supported cmdlets and parameters if using the library on-premises.
  • Fix on Get-CrmEntityKey
    The Attributes parameter contained an incorrect ArgumentCompleter
  • Use PSBoundParameters to check provided values
    Instead of using Nullable types and values to check if a parameter and value are provided, now we use the PSBoundParameters. As a result parameters are now no longer Nullable. If provided the values are used as-is.
  • Optimized cache use
    Metadata cache is now used with all Entity related metadata cmdlets.
    Cache initialization can be forced on Connect-CrmOrganization using the InitializeMetadataCache switch. Otherwise the cached is initialized on first use.
  • Get-CrmEntity with EntityTypeCode
  • OrganizationRequest and -Response PropertyAdapters to flatten/pivot the Parameters and Results, like with Entity Attributes.