Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

What about us programmers?

(0) ShareShare
ReportReport
Posted on by 1,030

            QueryByAttribute substitute = new QueryByAttribute("productsubstitute")            {
                ColumnSet = new ColumnSet("substitutedproductid"),
            };
            substitute.AddAttributeValue("productid", opptyProd.GetAttributeValue<EntityReference>("productid"));
            substitute.AddAttributeValue("direction", new OptionSetValue(0)); //uni-direction
            substitute.AddAttributeValue("salesrelationshiptype", new OptionSetValue(3)); //substitute

ErrorCode: 0x80040203
Message: Condition for attribute 'productsubstitute.productid': expected argument(s) of type 'System.Guid' but received 'Microsoft.Xrm.Sdk.EntityReference'.

It says right in the picture, it's a lookup:

itsAlookup.PNG

Are we supposed to hack and type randomly and course through error dumps like some web developer?

(apologies for the graphic quality.  It's the fields of the Product Relationship entity in the default solution)

*This post is locked for comments

  • Suggested answer
    Dynamics Objects 365 Profile Picture
    550 on at
    RE: What about us programmers?

    Thats why I prefer using FetchExpression to retrieve data :|

  • Martin Donnelly Profile Picture
    1,030 on at
    RE: What about us programmers?

    I'm not sure which cuts more to the quick, this issue or that David Jennaway is covering for it ;-)

    I could be convinced if one couldn't have gotten this far without having the existence of the "query model" thrust in ones face.  Someone should document when normal behavior has been suspended instead of relying a debugger.

  • David Jennaway Profile Picture
    14,065 on at
    RE: What about us programmers?

    In my view the may it is designed is reasonable. In one case you are submitting a query, and it makes sense for CRM to require purely the base types, as that is all the information that is required, and there would be some overhead in validating any excess information (such as a OptionSetValue or EntityReference). Also, the query model must work for all client environments, not solely the strongly typed .Net environment

    In the other case, you are using data returned from CRM, and CRM is helpfully providing extra information in the OptionSet and EntityReference types

  • Steve Le Monnier Profile Picture
    955 on at
    RE: What about us programmers?

    I understand your frustration, so don't shoot the messenger! :-)

    We've faced similar frustrations, what we ended up doing is building helper classes around the SDK to insulate the development team from all these strangenesses.

    If your working on lots of CRM based projects (like we do), it pays to have your own base classes what simplifies some of these processes.

    Visual Studio C# is really cool at allowing you to extend or even replace some of the key elements of the Entity namespace.

  • Martin Donnelly Profile Picture
    1,030 on at
    RE: What about us programmers?

    I disagree!  I am claiming that this is the way Dynamics 365 SDK has been compromised.

    An EntityReference DOES NOT contain an entity.  The contain guid ID, string Name, string LogicalName.  It is a class.  The QueryByAttribute behaves as if they are a guid not an instance of a class.

    Yes, an optionsetvalue "contains" a label and an integer index value.  Pretending that an optionsetvalue is its integer denies the fact that it is an instance of a class.

    That sort of sloppy denial of reality is what makes programming projects take longer to complete.

    Feel free to go look at the schema of productsubstitute.  Productid is a Lookup not a Uniqueidentifier; the other two are Option Sets not Whole Numbers.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: What about us programmers?

    Hi ,

    If I am understood correctly your question , this is the way Dynamics 365 SDK has been designed. If you talk about EntityReference its contains an entity record . Every entity has the primary key   id (GUID)  to identity the records,  you do not need to reference whole EntityReference object. For example when you are retrieving entity  using retrieve method you need to pass Id and the entity name  , you do not need to pass the entity reference . When you are doing relationship its nothing but internally stored the the primary key id  in the related entity , each entity  records can identify using unique key which is the id value (GUID).

    Similarly for optionsetvalue contains value and text  and internally its maintain optionset  value instead of text as its unique value for optionset.

  • Martin Donnelly Profile Picture
    1,030 on at
    RE: What about us programmers?

    Thank you.  I can read.

    The question was more to the point of some insight into why an EntityReference is not an EntityReference and why an OptionSetValue is not an OptionSetValue.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: What about us programmers?

    Hi,

    You need to pass GUID of product instead entity reference like below-

    // Get GUID of product

     Guid productid = opptyProd.GetAttributeValue<EntityReference>("productid").Id;

    substitute.AddAttributeValue("productid", productid);

    Similarly for optionset you need to pass the value of the optionset, instead optionsettype reference.So before pass retrieve the int type optionset value and then pass.

  • Martin Donnelly Profile Picture
    1,030 on at
    RE: What about us programmers?

    And this is truly insulting:

    ErrorCode: 0x80040203

    Message: Condition for attribute 'productsubstitute.direction': expected argument(s) of type 'System.Int32' but received 'Microsoft.Xrm.Sdk.OptionSetValue'.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans