0

C#からMicrosoftDynamics4.0に新しい連絡先を追加しました。コードから出席者を要求するにはどうすればよいですか?このような連絡先を作成しました。選択した予定の必須の出席者としてこの連絡先を追加するにはどうすればよいですか?

        CRM.CrmService service = GetService();

        var contactResult = new contact
        {
            emailaddress1 = userContact.Email
        };

        var requestContact = new RetrieveDuplicatesRequest
        {
            BusinessEntity = contactResult
            ,
            MatchingEntityName = EntityName.contact.ToString()
            ,
            PagingInfo = new PagingInfo
                             {
                                 PageNumber = 1,
                                 Count = 1
                             }
        };

        bool blnEmailExists = false;

        try
        {


            var response = (RetrieveDuplicatesResponse)
                                    service.Execute(requestContact);

            foreach (contact contactItem in response.DuplicateCollection.BusinessEntities)
            {
                blnEmailExists = true;
                contactResult.contactid = new Key();
                contactResult.contactid.Value = new Guid(contactItem.contactid.Value.ToString());
                contactResult.firstname = userContact.FirstName;
                contactResult.lastname = userContact.LastName;
                contactResult.fullname = userContact.FullName;
                contactResult.mobilephone = userContact.PhoneNumber;
                contactResult.description = userContact.Description;

                service.Update(contactResult);
            }

            if (!blnEmailExists)
            {
                contactResult.firstname = userContact.FirstName;
                contactResult.lastname = userContact.LastName;
                contactResult.fullname = userContact.FullName;
                contactResult.mobilephone = userContact.PhoneNumber;
                contactResult.description = userContact.Description;


                Guid contactId = service.Create(contactResult);

                if (!string.IsNullOrEmpty(userContact.Notes))
                    AppendToNotesSection(userContact.Notes, contactId, service);
            }
        }
        catch (System.Web.Services.Protocols.SoapException ex)
        {
            throw new Exception(ex.Message);
        }

ありがとう

4

1 に答える 1

0

activityPartyを介して更新でき、ついに見つけて修正しました。

CRM.CrmService service = GetService();

        appointment appointment = (appointment)service.Retrieve(EntityName.appointment.ToString(), activityid, new AllColumns());

        if(appointment == null)
        {
            throw new ArgumentNullException("Invalid Appointment");
        }

        contact contact = RegisterContact(userContact, service);

        activityparty[] activityParty = new activityparty[appointment.requiredattendees.Length + 1];
        activityParty[0] = new activityparty();
        activityParty[0].partyid = new Lookup();
        activityParty[0].partyid.Value = contact.contactid.Value;
        activityParty[0].partyid.type = "contact";
        Int16 index = 1;
        foreach (var item in appointment.requiredattendees)
        {
            //for avoiding duplicates
            if (item.partyid.Value != contact.contactid.Value)
            {
                activityParty[index] = new activityparty();
                activityParty[index].partyid = item.partyid;
                activityParty[index].partyid.Value = item.partyid.Value;
                activityParty[index].partyid.type = item.partyid.type;
                index++;
            }
        }



        appointment.requiredattendees = activityParty;

        try
        {
            service.Update(appointment);
        }
        catch (System.Web.Services.Protocols.SoapException ex)
        {
            Console.WriteLine(ex.Message + ". " + ex.Detail.InnerText);
        }
于 2012-12-27T09:14:35.913 に答える