Quantcast
Channel: CRM Development Forum
Viewing all articles
Browse latest Browse all 888

SQL Timeout when associate a role to newly created systemuser using CRM 2011 plug-in

$
0
0

Hi,
I really appreciate the help here.

Scenario:
I have a plug-in which runs on the Create message of a custom entity (new_xyz)
I wanted to create a systemuser on this Create message. The system systemuser creation works fine, but .Execute(associate) timing out.  Due to this I cannot see the newly created user in CRM (not present in SystemUserBase table, but can see in _CONFIG.SystemUserOrganizations).
This SQL timeout occur not only for associating role, for any operations after this systemuser creation (Like .Update(new_entity), .Execute(grantPermisison)  etc.)
When I debugged the plug-in code, after .Create(systemuser) the entry I saw in SystemUserBase table, but disappeared after timeout error. So I believe it's rolled back by transaction.

My Questions:
Can I create systemuser in an entity's Create plug-in message?
If not , what will be alternative?
My requirement is to share the new_xyz entity record with the members of a Distribution List automatically while it is created. So if any of the DL members are not an existing systemuser then create them. Is there any better way to achieve this?

Code snippet:

Guid buId = Guid.Parse("39E13E10-B79B-E111-9512-F4CE46B6E111");
Guid roleId = Guid.Parse("6ECBB2D5-179E-E111-9512-F4CE46B6E111");

Entity systemuser = new Entity("systemuser");

systemuser.Attributes.Add("domainname", userDomainName);
systemuser.Attributes.Add("firstname", firstName);
systemuser.Attributes.Add("lastname", lastName);
EntityReference businessUnit = new EntityReference("businessunit", buId);
systemuser.Attributes.Add("businessunitid",businessUnit);
Guid userId = Context.OrganizationService.Create(systemuser);                          

//Assign role
  AssociateRequest associate = new AssociateRequest()
  {
    Target = new EntityReference("systemuser", userId),
     RelatedEntities = new EntityReferenceCollection()
        {
           new EntityReference("role", roleId),
           },
                Relationship = new Relationship("systemuserroles_association")
        };
       Context.OrganizationService.Execute(associate);
     return userId;
Thanks in Advance
Rakesh Narayan

RN


Viewing all articles
Browse latest Browse all 888

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>