-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Scenario: I have the exact GUID of an "Option Set" type component that is added to a solution. All I need is to be able to use this option set component's GUID as an input somehow and then receive the name (or even display name) of that component as part of the output. I am able to retrieve the name of virtually every other component within this solution, but I consistently run into irritating errors no matter what I try.
Method 1:
Get-CrmRecord -EntityLogicalName optionsets -Id $component.objectid -Fields $EntityMetadata.PrimaryNameAttribute
Result 1:
************ FaultException1 - Retrieve : Trying to Read a Record. Entity = optionsets , ID =
d07a1fa2-2aa8-ef11-8a69-7c1e525b2662 |=> The entity with a name = 'optionsets' with namemapping = 'Logical' was not found
in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False,
Timestamp=66970612, MinActiveRowVersion=66970612, MetadataInstanceId=31372616, LastUpdated=2024-12-23 03:54:36.680,
OrgId=bd3e1fe7-bc94-4c53-abe3-c0be7e25f373
The entity with a name = 'optionsets' with namemapping = 'Logical' was not found in the MetadataCache.
MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=66970612,
MinActiveRowVersion=66970612, MetadataInstanceId=31372616, LastUpdated=2024-12-23 03:54:36.680,
OrgId=bd3e1fe7-bc94-4c53-abe3-c0be7e25f373[TerminalFailure] Failed to Execute Command - Retrieve :
RequestID=818a31cd-7560-43cc-8944-600a73c027a9 : Trying to Read a Record. Entity = optionsets , ID =
d07a1fa2-2aa8-ef11-8a69-7c1e525b2662 duration=00:00:00.2553776 ExceptionMessage = The entity with a name = 'optionsets'
with namemapping = 'Logical' was not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic,
StandardCache=True, IsLoadedInStagedContext = False, Timestamp=66970612, MinActiveRowVersion=66970612,
MetadataInstanceId=31372616, LastUpdated=2024-12-23 03:54:36.680, OrgId=bd3e1fe7-bc94-4c53-abe3-c0be7e25f373
The entity with a name = 'optionsets' with namemapping = 'Logical' was not found in the MetadataCache.
MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext = False, Timestamp=66970612,
MinActiveRowVersion=66970612, MetadataInstanceId=31372616, LastUpdated=2024-12-23 03:54:36.680,
OrgId=bd3e1fe7-bc94-4c53-abe3-c0be7e25f373
Method 2 (when the iteration is processing an "Option Set" type):
foreach ($Solution in $SolutionName)
{
$SolutionResult = Get-CrmRecords -EntityLogicalName solution -Fields * -conn $Connection -FilterAttribute uniquename -FilterOperator eq -FilterValue $Solution
$SolutionId = $SolutionResult.CrmRecords[0].ReturnProperty_Id
$SolutionComponents = Get-CrmRecords -EntityLogicalName solutioncomponent -Fields * -conn $Connection -FilterAttribute solutionid -FilterOperator eq -FilterValue $SolutionId
$RootComponents = $SolutionComponents.CrmRecords | Where-Object {$null -eq $_.rootsolutioncomponentid}
foreach ($Component in $RootComponents)
{
if ($null -eq $Component.componenttype)
{
$ComponentType = Get-CrmEntityName -EntityTypeCode $Component.componenttype_Property.Value.Value
} else
{
$ComponentType = $(($Component.componenttype.ToLower()) -replace ' ')
}
$EntityMetadata = Get-CrmEntityMetadata -EntityLogicalName $ComponentType
$fetchxml = '<fetch top="1"> <entity name="{0}" > <attribute name="{1}" /> <filter> <condition attribute="{2}" operator="eq" value="{3}" /> </filter> </entity> </fetch>' -f $EntityMetadata.LogicalName, $EntityMetadata.PrimaryNameAttribute, $EntityMetadata.PrimaryIdAttribute, $Component.objectid
$FilterQuery = "?$filter=$($EntityMetadata.PrimaryIdAttribute) eq '$($Component.objectid)'"
$QueryUrl = "$EnvironmentUrl/api/data/v9.2/$($EntityMetadata.EntitySetName.ToLower())?fetchXml=$fetchxml"
$ComponentName = $response.value | Select-Object -ExpandProperty $EntityMetadata.PrimaryNameAttribute
Write-Host $ComponentName
}
}
Result 2:
Invoke-RestMethod : {"error":{"code":"0x80040800","message":"The 'RetrieveMultiple' method does not support entities of
type 'optionset'. MessageProcessorCache returned MessageProcessor.Empty. "}}
At line:36 char:29
+ ... $response = Invoke-RestMethod -Method Get -Uri $QueryUrl -Headers @{
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExcepti
on
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Method 3:
$Connection.Retrieve($EntityMetadata.LogicalCollectionName, $Component.objectid, $Columns)
Result 3:
Exception calling "Retrieve" with "3" argument(s): "The entity with a name = 'optionsets' with namemapping = 'Logical' was
not found in the MetadataCache. MetadataCacheDetails: ProviderType=Dynamic, StandardCache=True, IsLoadedInStagedContext =
False, Timestamp=66970612, MinActiveRowVersion=66970612, MetadataInstanceId=371361, LastUpdated=2024-12-23 03:54:36.680,
OrgId=bd3e1fe7-bc94-4c53-abe3-c0be7e25f373"
At line:1 char:1
+ $Connection.Retrieve($EntityMetadata.LogicalCollectionName, $Componen ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : FaultException`1
For the record, I understand the entity type details (https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/reference/optionset?view=dataverse-latest) and that "RetrieveMultiple" does not support this entity type, but at the same time, I know Dataverse has a table named OptionSets that I can sort of query via PowerAutomate. There has got to be some way to use the Retrieve function or something similar to retrieve the name of a single option set component, especially when you have the object's GUID.