locked
How to set Team as entity owner programmatically RRS feed

  • Question

  • I want to add some outlook contacts to our CRM programmatically, but would like to set a Team as the owner. Unfortunately, the fields OwningTeam and OwningUser are read-only. The OwningUser is automatically set to my user id when I create the entity.

    Can anyone suggest a hint how to accomplish this?
    Tuesday, April 9, 2013 4:37 PM

Answers

  • Use "OwnerId"

    Contact contact = new Contact();
    contact.FirstName = "test";
    contact.LastName = "test";
    contact.OwnerId = new EntityReference(SystemUser.EntityLogicalName, new Guid("B3D927B0-E283-E111-B63B-00505685006C"));
     _serviceProxy.Create(contact);

    Then you can set the OwnerId to a SystemUser or Team


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, April 9, 2013 4:52 PM
    Moderator

All replies

  • Use "OwnerId"

    Contact contact = new Contact();
    contact.FirstName = "test";
    contact.LastName = "test";
    contact.OwnerId = new EntityReference(SystemUser.EntityLogicalName, new Guid("B3D927B0-E283-E111-B63B-00505685006C"));
     _serviceProxy.Create(contact);

    Then you can set the OwnerId to a SystemUser or Team


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Tuesday, April 9, 2013 4:52 PM
    Moderator
  • Can you assign the reocrd to a Team?

    Following code show how to assign a Lead to a Team. Assume the lead record is already created.

     AssignRequest assignRequest = new AssignRequest()
                {
                    Assignee = new EntityReference
                    {
                        LogicalName = Team.EntityLogicalName,
                        Id = Guid.Parse(System.Configuration.ConfigurationManager.AppSettings["TEAMID"])
                    },
                    Target = new EntityReference(Lead.EntityLogicalName, LeadId)
                };
                try
                {
                    _service.Execute(assignRequest);
                }
                catch (Exception ex)
                {
                }

    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.

    Tuesday, April 9, 2013 10:08 PM
  • Thanks - that solved my problem!
    Wednesday, April 10, 2013 7:38 AM