locked
Condition for attribute 'opportunity.opportunityid': expected argument(s) of type 'System.Guid' but received 'System.Object[]'. RRS feed

  • Question

  • User-893002196 posted

    Hi All,

    I got error:

     Condition for attribute 'opportunity.opportunityid': expected argument(s) of type 'System.Guid' but received 'System.Object[]'.

    I guest something wrong with my ConditionExpression Values = { opportunityfilter }.

    Please advise. Thank you. My code as below:-

    var opportunityfilter = crmOpportunities.ToArray()[0].Entities.Select(k => k.Attributes["opportunityid"]).Cast<Guid>().ToArray();   

    //  Set up column set   
    ColumnSet cols = new ColumnSet("opportunityid","...","...");   

    ConditionExpression oppCondition = new Microsoft.Xrm.Sdk.Query.ConditionExpression

                {

                    AttributeName ="opportunityid",

                    Operator =ConditionOperator.In,

                    Values = { opportunityfilter }

                };

    FilterExpression filter = new FilterExpression();

                filter.FilterOperator =LogicalOperator.And;

                filter.AddCondition(oppCondition);

    LinkEntity linkToOpportunity = new LinkEntity();

                linkToOpportunity.JoinOperator =JoinOperator.Inner;

                linkToOpportunity.LinkCriteria = filter;

                linkToOpportunity.LinkFromEntityName ="opportunityproduct";
                linkToOpportunity.LinkFromAttributeName ="opportunityid";

                linkToOpportunity.LinkToEntityName ="opportunity";

                linkToOpportunity.LinkToAttributeName ="opportunityid";

               

    //  Create query 

    QueryExpression query = new Microsoft.Xrm.Sdk.Query.QueryExpression()

                {

                    EntityName ="opportunityproduct",               ColumnSet = cols,                Criteria = filter

                };

    :

    :

                       query.PageInfo.PagingCookie = (pageNumber == 1) ?null : multiResponse.EntityCollection.PagingCookie;

                        query.PageInfo.PageNumber = pageNumber++;

                        multiRequest =new RetrieveMultipleRequest();

                        multiRequest.Query = query;

                        multiResponse = (RetrieveMultipleResponse)crmService.Execute(multiRequest);  <<----Error

    Regards,

    Micheale

    Thursday, July 30, 2015 11:41 PM

Answers

  • User-893002196 posted

    Solved!

    Replace condition expression with:-

    var opportunityfilter = crmOpportunities.ToArray()[0].Entities.Select(k => k.Attributes["opportunityid"]).Cast<Guid>().ToArray();

    onditionExpression oppCondition = new ConditionExpression("opportunityid", ConditionOperator.In, opportunityfilter);

    Thank you.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, July 31, 2015 12:00 AM