seanmcne / Microsoft.Xrm.Data.PowerShell

This module uses the CRM connection from Microsoft.Xrm.Tooling.CrmConnector.Powershell and provides common functions to create, delete, query, and update data as well as functions for common tasks such as publishing, and manipulating System & CRM User Settings, etc. The module should function for both Dynamics CRM Online and On-Premise environment.
201 stars 64 forks source link

cannot bind argument to parameter Value because it is null #525

Open parvezghumra opened 10 months ago

parvezghumra commented 10 months ago

Hi All and @seanmcne,

I'm fairly new to this PowerShell module so please bear with me. I've built a couple of custom scripts using this module: one to export data from a source environment and store it in source control, and a second to import that data from source control to a target environment.

I'm trying to use the following command to do an upsert based on the record's primary unique identifier column:

$output = Set-CrmRecord -EntityLogicalName $primaryEntityName -Id $recordId -Fields $fieldHash -Upsert

I've found that if there is at least one null column value in $fieldHash and the command attempts to create the record in the target environment because it does not already exist, then it fails with the following error:

cannot bind argument to parameter Value because it is null

I thought the whole point of the -upsert option was so that I do not need to query the existing data first manually myself first before then deciding whether to perform a create or update operation depending on whether or not the record exists, as this logic would be handled internally by the upsert option? Is this not the case? Do I really need to build logic to exclude null column values from $fieldHash if it's going to be a create operation and so I need to query the data in the target environment first?

Not sure if it makes a difference, but the way I'm setting the null column value is using the following sort of command: $fieldHash.Add("new_mycolumn", $null) Is this correct?

parvezghumra commented 10 months ago

@seanmcne @kenakamu Fixed in PR #526

seanmcne commented 10 months ago

@parvezghumra were you able to test to ensure this doesn't break anything when sending the request over?

Thanks!

parvezghumra commented 10 months ago

@seanmcne Yes, I tested it successfully for my use case as described in this issue above.