CRM 2011 : Assign record to another user

Con risposta CRM 2011 : Assign record to another user

  • venerdì 20 luglio 2012 14:16
     
      Contiene codice

    Hello,

    I'm developping a importation program.

    I can create without problem new account (for exemple), but i would like to assign it to someones else than me.
    I found this code, but it's not working :
    GuidUtilisateur = user guid of user i want to assign the record
    DonneeAAssigner = guid of the created account

            private static bool AssignerDonnee(Guid GuidUtilisateur, Guid DonneeAAssigner)
            {
                // Crée le SecurityPrincipal object.
                SecurityPrincipal assignee = new SecurityPrincipal();
                assignee.Type = SecurityPrincipalType.User;
    
                // PrincipalId est le guid de la personne auquelle on souhaite assigner le record
                assignee.PrincipalId = GuidUtilisateur;
                
                // Création de l'objectif de la requête
                TargetOwnedQuote target = new TargetOwnedQuote();
    
                // EntityId est le guid de la donnée à assigner
                target.EntityId = DonneeAAssigner;
    
                // Création de la requete
                AssignRequest assign = new AssignRequest();
    
                assign.Assignee = assignee;
                assign.Target = target;
          
                // Exécution de la requete
                AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
    
                return true;
            }

    I verified the guid of the user and i also verified the record is active.

    Here the error message:

    Thank you in advance,

    PS : I'm using the webservice of CRM 4.0 but i'm in CRM 2011.

Tutte le risposte

  • venerdì 20 luglio 2012 20:13
    Moderatore
     
      Contiene codice

    Hello,

    To get detailed error you can use following code:

    try
    {
    AssignResponse assignResponse = (AssignResponse)service.Execute(assign);
    }
    catch(SoapException ex)
    {
    throw new Exception(ex.Detail.InnerText);
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

  • lunedì 23 luglio 2012 06:42
     
     

    Hello,

    Thank you for your reply.
    When i'm catching the error. It say me that the target.EntityId is not existing.
    I assigned to the target.EntityId the guid of the created account.

    Thank you in advances.

  • lunedì 23 luglio 2012 07:32
    Moderatore
     
     Con risposta

    I have suggestion - you can assign responsible during creation of account using following code snippet:

    DynamicEntity a = new DynamicEntity('account');

    //Filling of other fields

    a["ownerid"] = new Owner(<Guid of owning user>);


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter

    • Contrassegnato come risposta KMAREC lunedì 23 luglio 2012 09:52
    •