Issue with a Create Post Plugin registered against SystemUser entity - OrganizationServiceFault exception with AssociateRequest

Answered Issue with a Create Post Plugin registered against SystemUser entity - OrganizationServiceFault exception with AssociateRequest

  • Thursday, March 22, 2012 9:27 AM
     
     

    Hi,

    CRM 2011,  on-premises 

    Requirement: The plugin logic is when a new User gets created in the system, a Security Role needs to be added against this new User record.

    This plugin is registered on Create message, Post stage, also registered with a Post Image step.

    When the plugin fires I can see the post image has details of the newly created user details including the Id. However when Execute method execute with AssociateRequest it fails with a OrganizationServiceFault exception message 

    “usersettings With Id = dce6e02a-f373-e111-988b-0050569e0028 Does Not Exist” , and then it roles back the transaction.

    The exception doesn’t have much details either. Any idea why the error is causing especially the plugin is registered as Post.

    //Code to Associate
    var userToRole = new AssociateRequest()
    {
    Target = new EntityReference(SystemUser.EntityLogicalName, userId),
    RelatedEntities = new EntityReferenceCollection()
    {
    new EntityReference(Role.EntityLogicalName, role.RoleId)
    },
    Relationship = new Relationship("systemuserroles_association")
    };
    service.Execute(userToRole);


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

All Replies

  • Friday, March 23, 2012 1:29 PM
     
     Proposed Answer

    I suggest changing Execution mode to Asynchronous, this should definatley make it work..

    we had similiar issue and we resolve it by making it run asynchronously, Let us know whether this works or not?

    Hope this helps..


    MayankP
    My Blog
    Follow Me on Twitter

    • Proposed As Answer by MayankP Wednesday, March 28, 2012 12:29 PM
    •  
  • Wednesday, March 28, 2012 6:48 AM
     
     Answered

    Thanks. I have changed this to a workflow which worked perfectly.


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

  • Saturday, August 18, 2012 2:08 AM
     
     

    thanks for your advice!!!


    • Edited by Sandy Zhuo Saturday, August 18, 2012 2:09 AM
    •  
  • Thursday, May 09, 2013 8:45 AM
     
     
    Hi, how did you do this as a workflow?
  • Friday, May 10, 2013 5:29 AM
     
     

    Hi, I have built a Custom Workflow assembly.  Created a Workflow (Process) for User Entity and selected when the Record is Created, and added my Custom Workflow Assembly as a step.


    Thomas T(MCBMSS) If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".