Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joined OptionSet Value is overwriten #371

Open
thuld opened this issue Jul 8, 2019 · 3 comments
Open

Joined OptionSet Value is overwriten #371

thuld opened this issue Jul 8, 2019 · 3 comments

Comments

@thuld
Copy link
Contributor

thuld commented Jul 8, 2019

Expected: Option-Set properties of joined-entities show "Display Name" of option.
Actual: Option-Set-Value is returned

The following code replaces the joined attribute value of type option-set (see Microsoft.Xrm.Data.Powershell.psm1, line 5258)

 ForEach($attribute in ($record.Keys|Select)){
    if($attribute.EndsWith("_Property")){
        if($record[$attribute].Value -is [Microsoft.Xrm.Sdk.AliasedValue]){
            #if aliased value BUT if it's an EntityRef... then ignore it 
            if($record[$attribute].Value.Value -isnot [Microsoft.Xrm.Sdk.EntityReference]){
                $attName = $attribute.Replace("_Property","")
                $record[$attName] = $record[$attribute].Value.Value
            }
                        
        }
        if($record[$attribute].Value -is [Microsoft.Xrm.Sdk.EntityReference]){
            $attName = $attribute.Replace("_Property","")
            $record[$attName] = $record[$attribute].Value.Name
        }
    }
}

Say I have two entities:

  1. "foo_softwareservice"
  2. "foo_service": This entity contains the option-set attribute "foo_group" (values are "ERP" and "CRM")

I use the following query

<fetch>
  <entity name="foo_softwareservice" >
    <attribute name="name" />
    <link-entity name="foo_service" from="foo_serviceid" to="ap_softwareserviceid" link-type="outer" alias="app" >
      <attribute name="foo_group" />
    </link-entity>
  </entity>
</fetch>

The mentioned code replaces the property "foo_group" with the option-set-values and overwrites the display-name.

Based on my understanding is the following code correct:

ForEach($attribute in ($record.Keys|Select)){
    if($attribute.EndsWith("_Property")) {

        if($record[$attribute].Value -is [Microsoft.Xrm.Sdk.AliasedValue]){
            ## ignore Entity-Ref. and option-sets 
            $ignoreTypes = @(
                'Microsoft.Xrm.Sdk.EntityReference',
                'Microsoft.Xrm.Sdk.OptionSetValue'
            )

            if($record[$attribute].Value.Value.GetType().Fullname -notin $ignoreTypes) {
                $attName = $attribute.Replace("_Property","")
                $record[$attName] = $record[$attribute].Value.Value
            }
        }
        if($record[$attribute].Value -is [Microsoft.Xrm.Sdk.EntityReference]){
            $attName = $attribute.Replace("_Property","")
            $record[$attName] = $record[$attribute].Value.Name
        }
    }
}
@seanmcne
Copy link
Owner

@thuld this one somehow slipped through - I’ll see if I can look into it this week. Is this a common scenario or one you are finding with global optionsets or just where entities share optionset attributes with the same name

@thuld
Copy link
Contributor Author

thuld commented Nov 19, 2019

@seanmcne Based on my findings is this the describe behavior when loading the options-sets from an linked entity

@seanmcne
Copy link
Owner

Very sorry for the delay on this, would it be possible for you to propose via a PR? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants