Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Comparing two fields of type party list

(0) ShareShare
ReportReport
Posted on by

Hello Guys,
 I have two OOB entities - Appointment and Service Activity. I am writing a plugin on the Appointment entity. One of the things I need to do in the plugin , is compare a pair of fields in appointment entity and Service Activity entity. In Appointment entity the field is called "Required Resources" and in the Service Activity it is called "Resource". Both the fields are of the type "Party List". Required resources contain multiple values (Stores Resources).Lets say R1,R2,R3. In service activity, Resource contains only one value. Either R1 or R2 or R3. How do I check if Service Activity contains any one of the resources from the collection of resources in the appointment record and is of type party type.

I have never heard of this type of field before. And when I try to create a new field , it is not part of the group like Date, Single line of text etc.

*This post is locked for comments

  • RE: Comparing two fields of type party list

    Yeah

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Comparing two fields of type party list

    Ok, out of ideas for now - may need to try it here. Looks like requiredattendees are missing there for some reason (even not missing.. they are just empty)

  • RE: Comparing two fields of type party list

    Failed. Infact it failed after getting party list count(0)

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Comparing two fields of type party list

    pre-image would work everywhere (it's still a pre-image.. pre-operation image)

    PS. It won't work for the create.. to be precise:)

  • RE: Comparing two fields of type party list

    Pre operation or pre validation? If its going to be pre-delete wouldn't preimages not work?

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Comparing two fields of type party list

    Any chance you can try moving that plugin to Pre-delete?

  • RE: Comparing two fields of type party list

    Hey Alex,

    I added a trace for partyList.Entities.Count..Result is 0!

    In my case it should be 3..

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Comparing two fields of type party list

    Hi Jim,

    could you add a trace for the number of items in

    partyList.Entities.ToList()

    ?

  • RE: Comparing two fields of type party list

    Hey Alex,

    A little background on my problem actually. THere are three entities which are involved in my problem. They are all OOB entities

    - recurringappointmentmaster, appointment and serviceappointment. My end goal is when a user deletes a recurringappointmentmaster

    record, the corresponding serviceappointment records' status must be flipped to cancelled. I hope you're familiar with how recurringappointmentmaster works

    and how they're associated with appointment. If not let me know , I can tell you. Anyways, now I made some modifications to the code- (Getting the requiredattendees from preimage of appointment record) . And made some modifications to the code as to where it is failing. Please find below code and the tracelog. So it looks like the system is not getting the requiredattendees data ?

    Code:

    using DevPlugIns.Common;

    using Microsoft.Crm.Sdk.Messages;

    using Microsoft.Xrm.Sdk;

    using Microsoft.Xrm.Sdk.Query;

    using System;

    using System.Collections.Generic;

    using System.Linq;

    namespace DevPlugIns

    {

    public class ChangeStatusofServiceActivity : IPlugin

    {

    const string PreImage = "PreImage";

    //running on appointment entity

    public void Execute(IServiceProvider serviceProvider)

    {

    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

    IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

    IOrganizationService _service = factory.CreateOrganizationService(context.InitiatingUserId);

    ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

    if (context.InputParameters != null)

    {

    tracingService.Trace("Entering method... ");

    Entity localAppointment = new Entity("appointment", context.PrimaryEntityId);

    Entity preImageAppointmentRecord = context.PreEntityImages[PreImage];

    tracingService.Trace("Appointment Record & PreImage Retrieved ");

    String appSubject = preImageAppointmentRecord.GetAttributeValue<String>(Constants.Appointment.Subject); //schemaname = "subject"

    tracingService.Trace("Subject of appointment retrieved ");

    EntityCollection partyList = preImageAppointmentRecord.GetAttributeValue<EntityCollection>(Constants.Appointment.RequiredAttendees); //SN: "requiredattendees";

    foreach (Entity resourceList in partyList.Entities)

    {

    tracingService.Trace("The list of resources from appointment record is retrieved." + resourceList.GetAttributeValue<EntityReference>("partyid").Id);

    }

    EntityCollection collectionOfServiceActivitites = _service.RetrieveMultiple((new FetchExpression(string.Format(Constants.FetchXmls.ServiceActivitiesFetch, appSubject))));

    //Retrieving Service activities where the subject name is equal, the subject field, scheduled start, scheduled end is retrieved from service activities is retrieved.

    if (collectionOfServiceActivitites.Entities.Count > 0)

    {

    foreach (Entity serviceactivity in collectionOfServiceActivitites.Entities)

    {

    EntityCollection activityResources = serviceactivity.GetAttributeValue<EntityCollection>(Constants.ServiceActivity.Resources);

    tracingService.Trace("Activity resources Collected" + activityResources);

    Entity foundParty = null;

    foreach (Entity activityResource in activityResources.Entities)

    {

    tracingService.Trace("Into the method to CHECK 2 ");

    var ResourceId = activityResource.GetAttributeValue<EntityReference>("partyid").Id;

    tracingService.Trace("Resource ID received" + ResourceId);

    foundParty = partyList.Entities.ToList().FirstOrDefault(party => (party.GetAttributeValue<EntityReference>("partyid")).Id == ResourceId);

    if (foundParty != null)

    {

    tracingService.Trace("It is into method of party list");

    DateTime serActEndField = serviceactivity.GetAttributeValue<DateTime>(Constants.ServiceActivity.ScheduledEnd).ToUniversalTime();

    String serActEndTime = serActEndField.ToString("t");

    tracingService.Trace("Service Activity End Time : " + serActEndTime);

    tracingService.Trace("About to check conditions to validate EC ");

    if (serviceactivity.GetAttributeValue<EntityReference>(Constants.ServiceActivity.EC) == localAppointment.GetAttributeValue<EntityReference>(Constants.Appointment.EC))

    {

    tracingService.Trace("Entering method to update values");

    CancelServiceActivity(_service, serviceactivity.ToEntityReference());

    }

    else

    {

    tracingService.Trace("Failed Center Check");

    }

    break;

    }

    else

    {

    tracingService.Trace("failed method");

    }

    }

    }

    // _service.Update(localAppointment);

    }

    }

    }

    private void CancelServiceActivity(IOrganizationService _service, EntityReference entityReference)

    {

    SetStateRequest appointmentRequest = new SetStateRequest

    {

    State = new OptionSetValue(2),

    Status = new OptionSetValue(9),

    EntityMoniker = entityReference

    };

    _service.Execute(appointmentRequest);

    }

    }

    }

    Trace:

    Entering method...

    Appointment Record & PreImage Retrieved

    Subject of appointment retrieved

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9c8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9e8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

    Activity resources CollectedMicrosoft.Xrm.Sdk.EntityCollection

    Into the method to CHECK 2

    Resource ID received9a8d6909-1860-e611-80c5-005056aa8521

    failed method

  • ashlega Profile Picture
    ashlega 34,477 on at
    RE: Comparing two fields of type party list

    Almost there, it seems.. What is the error you are getting? Add try-catch around that code and push error message to the tracing service..

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,430 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans