Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

adding criteria from another entity

(0) ShareShare
ReportReport
Posted on by

Hello Experts ,

I need to verify a condition (start_date) in the opportunity entity ,it shoud be among an interval (startdate & enddate) in a customized entity priceofservice.

 so the relation i have :  Opportunity 1-N opportunity product , opportunity Product N-1 Product , Product 1-N priceofservice entity.

 My code : 

 

public static decimal[] LoadpriceservicePriceOfOppProduct(LocalPluginContext context,
rea_oppproduct oppproduct)
{
Money servicePriceAdult = new Money(0);
Money serviceChild = new Money(0);
DateTime? validityPriceStartDate = new DateTime(1900, 01, 01);
DateTime? validityPriceSEndDate = new DateTime(1900, 01, 01);
decimal[] tabpriceservice = new decimal[2];

if (oppproduct.zz_priceservice==null)
{
oppproduct.zz_priceservice = false;
}
//
if (oppproduct.zz_priceservice.Value)
{
QueryExpression servicepriceQe = new QueryExpression(zz_serviceprice.EntityLogicalName);
servicepriceQe.ColumnSet = new ColumnSet();
servicepriceQe.ColumnSet.AddColumn(zz_serviceprice.Columns.zz_servicepriceadult);
servicepriceQe.ColumnSet.AddColumn(zz_serviceprice.Columns.zz_zz_servicepricechild);
servicepriceQe.Criteria = new FilterExpression();
servicepriceQe.Criteria.AddCondition(zz_serviceprice.Columns.rea_pricelistgroupid, ConditionOperator.Equal, oppproduct.rea_pricelistgroupid.Id);
servicepriceQe.Criteria.AddCondition(zz_serviceprice.Columns.rea_residenceid, ConditionOperator.Equal, oppproduct.rea_Residence.Id);
servicepriceQe.Criteria.AddCondition(zz_serviceprice.Columns.statecode, ConditionOperator.Equal, (int)zz_servicepriceState.Active);

EntityCollection serviceprice = context.OrganizationService.RetrieveMultiple(servicepriceQe);
if (serviceprice.Entities.Count == 0)
{

}
priceservicePriceAdult = (Money)serviceprice.Entities.First()[zz_serviceprice.Columns.zz_servicepriceadult];
priceserviceChild = ((Money)serviceprice.Entities.First()[zz_serviceprice.Columns.zz_zz_servicepricechild] == null) ? priceserviceChild : (Money)serviceprice.Entities.First()[zz_serviceprice.Columns.zz_zz_servicepricechild];
tabpriceservice[0] = priceservicePriceAdult.Value;
tabpriceservice[1] = priceserviceChild.Value;
}
else
{

}

return tabpriceservice;
}

I need to add the criteria to my query.

Thank you for your help!

 

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    on at
    RE: adding criteria from another entity

    Thank you Ravi , i will pass by the fetch .

  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: adding criteria from another entity

    Hi,

    I would suggest to build your query using advance find and then use fetchxml to retrieve the required record. It's comparatively easy than building a query expression with multiple relationship.

    You can also refer below fetchxml which I build in my test environment for this requirement. You need to paramterize the date and opportunity id  and obviously schemaname of your custom entity/ fields.

    ==========

    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">

     <entity name="new_testentity">

       <attribute name="new_testentityid" />

       <attribute name="new_name" />

       <attribute name="createdon" />

       <filter type="and">

         <condition attribute="new_startdate" operator="on-or-after" value="2018-10-16" />

         <condition attribute="new_enddate" operator="on-or-before" value="2018-10-16" />

       </filter>

       <link-entity name="product" from="productid" to="new_product" link-type="inner" alias="aa">

         <link-entity name="opportunityproduct" from="productid" to="productid" link-type="inner" alias="ab">

           <filter type="and">

             <condition attribute="opportunityid" operator="eq" value="{112D12C4-7F95-E811-A961-000D3AE05E81}" />

           </filter>

         </link-entity>

       </link-entity>

     </entity>

    </fetch>

    =============

    Hope this helps.

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