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)

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

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    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.

  • Verified answer
    Community Member Profile Picture
    on at

    Thank you Ravi , i will pass by the fetch .

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