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 Service Activity Appointmnt - Party Lists - Multiple resourses

(0) ShareShare
ReportReport
Posted on by 140

Hi All,


Hoping you can support on the best c# method for this using the organisation service proxy.

I am in the process of creating a contact, creating an account, linking them together and then creating the service activity appointment. I have successfully created the contact, account and the relationships between them, however I have stumbled on creating the service activity appointment.

I am having problems saving the related party lists such as adding 2 resources at once; a training room and a teacher. I would also like confirmation on whether I can use only the contact and service ID when linking them to the service activity appointment.

To start testing, I have hard coded the service activity name I would like to use when querying it to receive the ID but this isn't the issue. Please see what I have so far:

[code]

//Create the service appointment
                //Does Service already exist?
                QueryExpression serviceQuery = new QueryExpression
                {
                     EntityName = "service",
                     ColumnSet = new ColumnSet("serviceid"),
                     Criteria = new FilterExpression()
                 };
 
                 serviceQuery.Criteria.AddCondition("name", ConditionOperator.Equal, "A Course");
                 EntityCollection resultService = _service.RetrieveMultiple(serviceQuery);
                 Entity resultServiceID;
//If it already exists, use it if (resultService.Entities.Count > 0) { //result is the account ID resultServiceID = _service.RetrieveMultiple(serviceQuery).Entities.FirstOrDefault(); sID = resultServiceID.Id; Entity serviceActivity = new Entity("serviceappointment"); serviceActivity.Attributes["subject"] = "Customer Appointment 1"; serviceActivity.Attributes["scheduledstart"] = "25/03/2015 00:00 AM"; serviceActivity.Attributes["scheduledend"] = "26/03/2015 00:00 AM"; serviceActivity.Attributes["name"] = sID;

[/code]


I have already queried the equipment, systemuser and service entities to retrive the room to use, the teacher to use and the course to user respectively.
So I the ID and Logical names to hand. However should I be getting or recreating this data from/within the Activityparty entity?

I have tried these methods but they didn't work:

[code]
var customerParty = {
          PartyId = new EntityReference(contact.LogicalName, _contactId)
};

Guid[] parties = { rID, uID } ;
serviceActivity.Attributes["resoures"] =  parties ; 

[/code]

I also have tried to use the EntityReferenceCollection and Relationship methods to associate them together but realised I needed the service appointment ID which wouldn't be created at that point.

If anyone could please advise on the best method for this, it would be much appreciated.

Sorry I do not have any error messages, it just processes the contact and account as normal but the service calendar is always empty.

Regards,
Steph


*This post is locked for comments

I have the same question (0)
  • StephNicolaou Profile Picture
    140 on at

    Dear all,

    I have made progress with this.

    Three things that I have done wrong, two I have corrected the other I am working on.

    1. I realised it did not like the date values as a string... oops! This one is embarrassingly obvious.

    2. I add a party list just like so:

    Entity userActivity = new Entity("activityparty");

    userActivity.Attributes["partyid"] = new EntityReference(resultUserID.LogicalName, uID);

    Entity roomActivity = new Entity("activityparty");

    roomActivity.Attributes["partyid"] = new EntityReference(resultRoomID.LogicalName, rID);

    Entity[] parties = { roomActivity, userActivity } ;

    serviceActivity.Attributes["resources"] =  parties ;

    PROBLEM: The service appointment now appears in the calendar... without the service...

    3. It does not like the service value. I receive the error, "General failing in scheduling engine" within the CRM... I hope I am not going to brake it by trying different things now...

    So far I have tried:

    serviceActivity.Attributes["serviceid"] = sID;

    and...

    Entity activity = new Entity("service");

    activity.Attributes["serviceid"] = new EntityReference(resultServiceID.LogicalName, sID);

    serviceActivity.Attributes["serviceid"] = activity;

    At least I know what to look out for now.

  • StephNicolaou Profile Picture
    140 on at

    Hi All,

    Just to confirm, I complete the problem from my last post, I already had it really:

    [code]serviceActivity.Attributes["serviceid"] = new EntityReference(resultServiceID.LogicalName, sID); [/code]

    Now all I need to do is set the status however trying to relate the msdn example to the service activity entity is not so clear:

    [code]

    // Create the Request Object

               SetStateRequest state = new SetStateRequest();

               // Set the Request Object's Properties

               state.State = new OptionSetValue((int)IncidentState.Active);

               state.Status =

                   new OptionSetValue((int)incident_statuscode.WaitingforDetails);

               // Point the Request to the case whose state is being changed

               state.EntityMoniker = caseReference;

               // Execute the Request

               SetStateResponse stateSet = (SetStateResponse)_serviceProxy.Execute(state);

    [/code]

    I looked into the incident entity just to understand the methods used above but cannot find any relative values to incident_statuscode. Is case reference Incidentid? And where s IncidentState defined?

    I'll keep updated for anyone going to the same process even though I am not getting any responses, lol.

    Regards,

    Steph

  • Verified answer
    StephNicolaou Profile Picture
    140 on at

    Just for anyone looking else looking into this, I have shown the solution I found below.

    [code]

    Microsoft.Xrm.Sdk.EntityReference moniker = new EntityReference();

                       moniker.LogicalName = "serviceappointment";

                       moniker.Id =   _activityId;

                       Microsoft.Xrm.Sdk.OrganizationRequest request

                         = new Microsoft.Xrm.Sdk.OrganizationRequest() { RequestName = "SetState" };

                       request["EntityMoniker"] = moniker;

                       OptionSetValue state = new OptionSetValue(3);

                       OptionSetValue status = new OptionSetValue(4);

                       request["State"] = state;

                       request["Status"] = status;

                       _service.Execute(request);

    [/code]

    Now I am only looking into the capacitys as it says my resource is busy but this is a different issue I will look into.

  • Community Member Profile Picture
    on at

    hi Stephani, congratulations on getting through the issues - thank you for sharing the updates with your progress.

    Wondering if you are able to find the root cause for the capacity issue?

    regards,

    harihar

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