web
You’re offline. This is a read only version of the page.
close
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

I have the same question (0)
  • Martin Donnelly Profile Picture
    1,030 on at

    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'.

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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

    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

    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

    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.

  • Steve Le Monnier Profile Picture
    959 on at

    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.

  • David Jennaway Profile Picture
    14,065 on at

    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

  • Martin Donnelly Profile Picture
    1,030 on at

    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.

  • Suggested answer
    Dynamics Objects 365 Profile Picture
    550 on at

    Thats why I prefer using FetchExpression to retrieve data :|

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans