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 an extra condition to a linked entity c# plugin

(0) ShareShare
ReportReport
Posted on by 11,323

I have a c# query below and would like to know how to add another condition to a linked entity. Cant seem to get it to work.

          Entity entity = (Entity)context.InputParameters["Target"];

            tracer.Trace("Getting Agreement Schedule Dates...");

            //********* Get Agreement Invoice Dates *********
            QueryExpression query = new QueryExpression();
            query.EntityName = "f1_agreementscheduledate";
            query.ColumnSet.Columns.Add("f1_agreementscheduledateid");
            query.ColumnSet.Columns.Add("f1_workorder");
            query.ColumnSet.Columns.Add("statecode");
            query.ColumnSet.Columns.Add("f1_status");

            query.LinkEntities.Add(new LinkEntity("f1_agreementscheduledate", "f1_agreementschedulesetup", "f1_schedulesetup", "f1_agreementschedulesetupid", JoinOperator.Inner));
            query.LinkEntities[0].EntityAlias = "AgreementScheduleSetup";

            query.LinkEntities[0].LinkCriteria = new FilterExpression();
            query.LinkEntities[0].LinkCriteria.FilterOperator = LogicalOperator.And;
            query.LinkEntities[0].LinkCriteria.Conditions.Add
            (
                new ConditionExpression("f1_agreementschedulesetupid", ConditionOperator.Equal, entity.Id)
//ADD ANOTHER CONDITION HERE
);


*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    Hi Thomas,

    Try the code below. You can use Filter Expression for that.

    query.LinkEntities[0].LinkCriteria.Filters.Add(

                       new FilterExpression()

                       {

                           FilterOperator = LogicalOperator.And,

                           Conditions =

                           {

                               new ConditionExpression("f1_agreementschedulesetupid", ConditionOperator.Equal, entity.Id),

                               new ConditionExpression("f1_2", ConditionOperator.Equal, entity.Id),

                               new ConditionExpression("f1_3", ConditionOperator.Equal, entity.Id)

                           }

                       }

                   );

    Please mark as Verified if this helps.

    Thanks,

    Himanshu Prajapati

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at
     //********* Get Agreement Invoice Dates *********
    QueryExpression query = new QueryExpression("f1_agreementscheduledate");
    query.ColumnSet = new ColumnSet("f1_agreementscheduledateid", "f1_workorder", "statecode", "f1_status");
    
    LinkEntity linkSetup = query.AddLink("f1_agreementschedulesetup", "f1_schedulesetup", "f1_agreementschedulesetupid", JoinOperator.Inner);
    linkSetup.EntityAlias = "AgreementScheduleSetup"; // you should use lowercase here to keep consistent with the other names
    linkSetup.LinkCriteria.FilterOperator = LogicalOperator.And; // And is the default, so you can comment this line if you want
    linkSetup.LinkCriteria.AddCondition("f1_agreementschedulesetupid", ConditionOperator.Equal, entity.Id);
    // second condition
    linkSetup.LinkCriteria.AddCondition("yourattribute", ConditionOperator.Equal, "yourvalue");

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