CRM 2011 set owner on create of custom activity RRS feed

  • Question

  • I have some code originally written for CRM 4 then moved to CRM 2011 UR 6 that creates a custom activity (printcard). The code creates the activity and assigns the owner to be a team. This has worked great until we upgraded to UR 18. We now get an error of invalid owner type id. I've tried changing the code to LINQ, but get the same results. I've tried setting the owningteam lookup, but it's set to the systemuser instead. The guid is a valid team guid. Ideas on what's causing the issue?  

    BusinessObjects.CRMSdk.xxx_printcard printCard = new BusinessObjects.CRMSdk.xxx_printcard();

                    // Set up the CRM Service.
                    CrmService service = new CrmService();

                    service.Credentials = System.Net.CredentialCache.DefaultCredentials;

                    // Create an authentication token for your organization.
                    BusinessObjects.CRMSdk.CrmAuthenticationToken token = new BusinessObjects.CRMSdk.CrmAuthenticationToken();
                    token.OrganizationName = OrgName;

                    // Use Active Directory authentication.
                    token.AuthenticationType = 0;

                    service.CrmAuthenticationTokenValue = token;
                    service.Url = CRMUrl;

                    printCard.xxx_actor = new Lookup();
                    printCard.xxx_actor.Value = ActorID;
                    printCard.xxx_actor.type = EntityName.contact.ToString();

                    printCard.subject = ActivitySubject;

                    printCard.regardingobjectid = new Lookup();
                    printCard.regardingobjectid.Value = ActorID;
                    printCard.regardingobjectid.type = EntityName.contact.ToString();

                    DateTime DueDate = DateTime.Now.AddDays(3);

                    printCard.scheduledend = new CrmDateTime();
                    printCard.scheduledend.Value = DueDate.ToString();

                    printCard.xxx_cardtype = new Picklist();
                    printCard.xxx_cardtype.Value = 100000000;
                    printCard.ownerid = new Owner();
                    printCard.ownerid.Value = TeamID;
                    printCard.ownerid.type = EntityName.team.ToString();

                    printCard.xxx_batchid = new Lookup();
                    printCard.xxx_batchid.Value = BatchID;
                    printCard.xxx_batchid.type = EntityName.xxx_printcardbatch.ToString();

                    printCard.xxx_actorpaidtodate = new CrmDateTime();
                    printCard.xxx_actorpaidtodate.Value = PaidThruDate.ToString();

                    TargetCreatexxx_printcard target = new TargetCreatexxx_printcard();
                    target.xxx_printcard = printCard;

                    CreateRequest createRequest = new CreateRequest();
                    createRequest.Target = target;

    • Edited by Ben Cook Wednesday, January 21, 2015 6:27 PM
    Wednesday, January 21, 2015 6:25 PM

All replies

  • You may want to try creating the record first then assigning it to a new owner, i.e.:

                        // Create the Request Object and Set the Request Object's Properties
                        AssignRequest assign = new AssignRequest
                                Assignee = new EntityReference(SystemUser.EntityLogicalName,
                                Target = new EntityReference(Account.EntityLogicalName,
                        // Execute the Request

    Thursday, January 22, 2015 7:41 PM
  • I thought about that, but it's 2 requests to do what should be handled in one. We import large payment files for this client on a regular basis so I need to keep the code as efficient as we can. 
    Tuesday, January 27, 2015 8:08 PM