CRM Console App setting Owner of new record

Answered CRM Console App setting Owner of new record

  • quarta-feira, 25 de julho de 2012 18:55
     
     

    How do I set the owner of a record that I'm creating in a console app?  Do I use CrmEntityReference?

    :

    Guid OWNERID = (Guid)myReader["owner"]; //GUID returned from SQL SP dataset
                                    
                                    var CONTACT = new Contact()
                                    {
                                            //set Contact fields here
                                    };
                                    CONTACT.OwnerId = new Microsoft.Xrm.Client.CrmEntityReference("SystemUser", OWNERID);   
                                    xrm.AddObject(CONTACT);


    David Withers

Todas as Respostas

  • quarta-feira, 25 de julho de 2012 19:42
     
     

    You need to use the AssignRequest, see MSDN http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.assignrequest.aspx with something like this...

                       // Create the Request Object and Set the Request Object's Properties
                        AssignRequest assign = new AssignRequest
                            {
                                Assignee = new EntityReference(SystemUser.EntityLogicalName, _otherUserId),
                                Target = new EntityReference(Account.EntityLogicalName, _accountId)
                            };

                        // Execute the Request
                        _service.Execute(assign);

                      // where _service is the OrganizationServiceProxy

    You can get examples for these in the SDK documentation @ http://www.microsoft.com/en-us/download/details.aspx?id=24004

    Thanks,

    RBaliga

  • quinta-feira, 26 de julho de 2012 04:37
     
     
    so when you are creating a record you cannot set the owner?

    David Withers

  • quinta-feira, 26 de julho de 2012 15:53
     
     Respondido

    Found the answer (not from copying MS SDK websites)

    Guid OWNERID = (Guid)myReader["owner"];

    OwnerId = new Microsoft.Xrm.Client.CrmEntityReference(SystemUser.EntityLogicalName,OWNERID) 


    David Withers

    • Marcado como Resposta David Withers quinta-feira, 26 de julho de 2012 15:53
    •